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);
45 typedef struct _xsltemplate
47 IXSLTemplate IXSLTemplate_iface;
53 typedef struct _xslprocessor
55 IXSLProcessor IXSLProcessor_iface;
58 xsltemplate *stylesheet;
63 static HRESULT XSLProcessor_create(xsltemplate*, IXSLProcessor**);
65 static inline xsltemplate *impl_from_IXSLTemplate( IXSLTemplate *iface )
67 return CONTAINING_RECORD(iface, xsltemplate, IXSLTemplate_iface);
70 static inline xslprocessor *impl_from_IXSLProcessor( IXSLProcessor *iface )
72 return CONTAINING_RECORD(iface, xslprocessor, IXSLProcessor_iface);
75 static void xsltemplate_set_node( xsltemplate *This, IXMLDOMNode *node )
77 if (This->node) IXMLDOMNode_Release(This->node);
79 if (node) IXMLDOMNode_AddRef(node);
82 static HRESULT WINAPI xsltemplate_QueryInterface(
87 xsltemplate *This = impl_from_IXSLTemplate( iface );
88 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
90 if ( IsEqualGUID( riid, &IID_IXSLTemplate ) ||
91 IsEqualGUID( riid, &IID_IDispatch ) ||
92 IsEqualGUID( riid, &IID_IUnknown ) )
98 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
102 IUnknown_AddRef((IUnknown*)*ppvObject);
106 static ULONG WINAPI xsltemplate_AddRef( IXSLTemplate *iface )
108 xsltemplate *This = impl_from_IXSLTemplate( iface );
109 return InterlockedIncrement( &This->ref );
112 static ULONG WINAPI xsltemplate_Release( IXSLTemplate *iface )
114 xsltemplate *This = impl_from_IXSLTemplate( iface );
117 ref = InterlockedDecrement( &This->ref );
120 if (This->node) IXMLDOMNode_Release( This->node );
127 static HRESULT WINAPI xsltemplate_GetTypeInfoCount( IXSLTemplate *iface, UINT* pctinfo )
129 xsltemplate *This = impl_from_IXSLTemplate( iface );
131 TRACE("(%p)->(%p)\n", This, pctinfo);
137 static HRESULT WINAPI xsltemplate_GetTypeInfo(
139 UINT iTInfo, LCID lcid,
140 ITypeInfo** ppTInfo )
142 xsltemplate *This = impl_from_IXSLTemplate( iface );
144 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
146 return get_typeinfo(IXSLTemplate_tid, ppTInfo);
149 static HRESULT WINAPI xsltemplate_GetIDsOfNames(
151 REFIID riid, LPOLESTR* rgszNames,
152 UINT cNames, LCID lcid, DISPID* rgDispId )
154 xsltemplate *This = impl_from_IXSLTemplate( iface );
158 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
161 if(!rgszNames || cNames == 0 || !rgDispId)
164 hr = get_typeinfo(IXSLTemplate_tid, &typeinfo);
167 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
168 ITypeInfo_Release(typeinfo);
174 static HRESULT WINAPI xsltemplate_Invoke(
176 DISPID dispIdMember, REFIID riid, LCID lcid,
177 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
178 EXCEPINFO* pExcepInfo, UINT* puArgErr )
180 xsltemplate *This = impl_from_IXSLTemplate( iface );
184 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
185 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
187 hr = get_typeinfo(IXSLTemplate_tid, &typeinfo);
190 hr = ITypeInfo_Invoke(typeinfo, &This->IXSLTemplate_iface, dispIdMember,
191 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
192 ITypeInfo_Release(typeinfo);
198 static HRESULT WINAPI xsltemplate_putref_stylesheet( IXSLTemplate *iface,
201 xsltemplate *This = impl_from_IXSLTemplate( iface );
203 TRACE("(%p)->(%p)\n", This, node);
207 xsltemplate_set_node(This, NULL);
211 /* FIXME: test for document type */
212 xsltemplate_set_node(This, node);
217 static HRESULT WINAPI xsltemplate_get_stylesheet( IXSLTemplate *iface,
220 xsltemplate *This = impl_from_IXSLTemplate( iface );
222 FIXME("(%p)->(%p): stub\n", This, node);
226 static HRESULT WINAPI xsltemplate_createProcessor( IXSLTemplate *iface,
227 IXSLProcessor **processor)
229 xsltemplate *This = impl_from_IXSLTemplate( iface );
231 TRACE("(%p)->(%p)\n", This, processor);
233 if (!processor) return E_INVALIDARG;
235 return XSLProcessor_create(This, processor);
238 static const struct IXSLTemplateVtbl xsltemplate_vtbl =
240 xsltemplate_QueryInterface,
243 xsltemplate_GetTypeInfoCount,
244 xsltemplate_GetTypeInfo,
245 xsltemplate_GetIDsOfNames,
248 xsltemplate_putref_stylesheet,
249 xsltemplate_get_stylesheet,
250 xsltemplate_createProcessor
253 HRESULT XSLTemplate_create(IUnknown *pUnkOuter, void **ppObj)
257 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
259 if(pUnkOuter) FIXME("support aggregation, outer\n");
261 This = heap_alloc( sizeof (*This) );
263 return E_OUTOFMEMORY;
265 This->IXSLTemplate_iface.lpVtbl = &xsltemplate_vtbl;
269 *ppObj = &This->IXSLTemplate_iface;
271 TRACE("returning iface %p\n", *ppObj);
276 /*** IXSLProcessor ***/
277 static HRESULT WINAPI xslprocessor_QueryInterface(
278 IXSLProcessor *iface,
282 xslprocessor *This = impl_from_IXSLProcessor( iface );
283 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
285 if ( IsEqualGUID( riid, &IID_IXSLProcessor ) ||
286 IsEqualGUID( riid, &IID_IDispatch ) ||
287 IsEqualGUID( riid, &IID_IUnknown ) )
293 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
294 return E_NOINTERFACE;
297 IUnknown_AddRef((IUnknown*)*ppvObject);
301 static ULONG WINAPI xslprocessor_AddRef( IXSLProcessor *iface )
303 xslprocessor *This = impl_from_IXSLProcessor( iface );
304 return InterlockedIncrement( &This->ref );
307 static ULONG WINAPI xslprocessor_Release( IXSLProcessor *iface )
309 xslprocessor *This = impl_from_IXSLProcessor( iface );
312 ref = InterlockedDecrement( &This->ref );
315 if (This->input) IXMLDOMNode_Release(This->input);
316 if (This->output) IStream_Release(This->output);
317 IXSLTemplate_Release(&This->stylesheet->IXSLTemplate_iface);
324 static HRESULT WINAPI xslprocessor_GetTypeInfoCount( IXSLProcessor *iface, UINT* pctinfo )
326 xslprocessor *This = impl_from_IXSLProcessor( iface );
328 TRACE("(%p)->(%p)\n", This, pctinfo);
334 static HRESULT WINAPI xslprocessor_GetTypeInfo(
335 IXSLProcessor *iface,
336 UINT iTInfo, LCID lcid,
337 ITypeInfo** ppTInfo )
339 xslprocessor *This = impl_from_IXSLProcessor( iface );
341 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
343 return get_typeinfo(IXSLProcessor_tid, ppTInfo);
346 static HRESULT WINAPI xslprocessor_GetIDsOfNames(
347 IXSLProcessor *iface,
348 REFIID riid, LPOLESTR* rgszNames,
349 UINT cNames, LCID lcid, DISPID* rgDispId )
351 xslprocessor *This = impl_from_IXSLProcessor( iface );
355 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
358 if(!rgszNames || cNames == 0 || !rgDispId)
361 hr = get_typeinfo(IXSLProcessor_tid, &typeinfo);
364 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
365 ITypeInfo_Release(typeinfo);
371 static HRESULT WINAPI xslprocessor_Invoke(
372 IXSLProcessor *iface,
373 DISPID dispIdMember, REFIID riid, LCID lcid,
374 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
375 EXCEPINFO* pExcepInfo, UINT* puArgErr )
377 xslprocessor *This = impl_from_IXSLProcessor( iface );
381 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
382 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
384 hr = get_typeinfo(IXSLProcessor_tid, &typeinfo);
387 hr = ITypeInfo_Invoke(typeinfo, &This->IXSLProcessor_iface, dispIdMember,
388 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
389 ITypeInfo_Release(typeinfo);
395 static HRESULT WINAPI xslprocessor_put_input( IXSLProcessor *iface, VARIANT input )
397 xslprocessor *This = impl_from_IXSLProcessor( iface );
398 IXMLDOMNode *input_node;
401 TRACE("(%p)->(%s)\n", This, debugstr_variant(&input));
403 /* try IXMLDOMNode directly first */
404 if (V_VT(&input) == VT_UNKNOWN)
405 hr = IUnknown_QueryInterface(V_UNKNOWN(&input), &IID_IXMLDOMNode, (void**)&input_node);
406 else if (V_VT(&input) == VT_DISPATCH)
407 hr = IDispatch_QueryInterface(V_DISPATCH(&input), &IID_IXMLDOMNode, (void**)&input_node);
410 IXMLDOMDocument *doc;
412 hr = DOMDocument_create(&CLSID_DOMDocument, NULL, (void**)&doc);
417 hr = IXMLDOMDocument_load(doc, input, &b);
419 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&input_node);
420 IXMLDOMDocument_Release(doc);
426 if (This->input) IXMLDOMNode_Release(This->input);
427 This->input = input_node;
433 static HRESULT WINAPI xslprocessor_get_input( IXSLProcessor *iface, VARIANT *input )
435 xslprocessor *This = impl_from_IXSLProcessor( iface );
437 FIXME("(%p)->(%p): stub\n", This, input);
441 static HRESULT WINAPI xslprocessor_get_ownerTemplate(
442 IXSLProcessor *iface,
443 IXSLTemplate **template)
445 xslprocessor *This = impl_from_IXSLProcessor( iface );
447 FIXME("(%p)->(%p): stub\n", This, template);
451 static HRESULT WINAPI xslprocessor_setStartMode(
452 IXSLProcessor *iface,
456 xslprocessor *This = impl_from_IXSLProcessor( iface );
458 FIXME("(%p)->(%s %s): stub\n", This, wine_dbgstr_w(p), wine_dbgstr_w(uri));
462 static HRESULT WINAPI xslprocessor_get_startMode(
463 IXSLProcessor *iface,
466 xslprocessor *This = impl_from_IXSLProcessor( iface );
468 FIXME("(%p)->(%p): stub\n", This, p);
472 static HRESULT WINAPI xslprocessor_get_startModeURI(
473 IXSLProcessor *iface,
476 xslprocessor *This = impl_from_IXSLProcessor( iface );
478 FIXME("(%p)->(%p): stub\n", This, uri);
482 static HRESULT WINAPI xslprocessor_put_output(
483 IXSLProcessor *iface,
486 xslprocessor *This = impl_from_IXSLProcessor( iface );
490 FIXME("(%p)->(%s): semi-stub\n", This, debugstr_variant(&output));
492 switch (V_VT(&output))
499 hr = IUnknown_QueryInterface(V_UNKNOWN(&output), &IID_IStream, (void**)&stream);
507 if (This->output) IStream_Release(This->output);
508 This->output = stream;
514 static HRESULT WINAPI xslprocessor_get_output(
515 IXSLProcessor *iface,
518 xslprocessor *This = impl_from_IXSLProcessor( iface );
520 FIXME("(%p)->(%p): stub\n", This, output);
524 static HRESULT WINAPI xslprocessor_transform(
525 IXSLProcessor *iface,
528 xslprocessor *This = impl_from_IXSLProcessor( iface );
532 TRACE("(%p)->(%p)\n", This, ret);
534 if (!ret) return E_INVALIDARG;
536 hr = IXMLDOMNode_transformNode(This->input, This->stylesheet->node, &p);
541 /* output to stream */
542 hr = IStream_Write(This->output, p, SysStringByteLen(p), &len);
543 *ret = len == SysStringByteLen(p) ? VARIANT_TRUE : VARIANT_FALSE;
547 *ret = VARIANT_FALSE;
552 static HRESULT WINAPI xslprocessor_reset( IXSLProcessor *iface )
554 xslprocessor *This = impl_from_IXSLProcessor( iface );
556 FIXME("(%p): stub\n", This);
560 static HRESULT WINAPI xslprocessor_get_readyState(
561 IXSLProcessor *iface,
564 xslprocessor *This = impl_from_IXSLProcessor( iface );
566 FIXME("(%p)->(%p): stub\n", This, state);
570 static HRESULT WINAPI xslprocessor_addParameter(
571 IXSLProcessor *iface,
576 xslprocessor *This = impl_from_IXSLProcessor( iface );
578 FIXME("(%p)->(%s %s %s): stub\n", This, wine_dbgstr_w(p), debugstr_variant(&var),
583 static HRESULT WINAPI xslprocessor_addObject(
584 IXSLProcessor *iface,
588 xslprocessor *This = impl_from_IXSLProcessor( iface );
590 FIXME("(%p)->(%p %s): stub\n", This, obj, wine_dbgstr_w(uri));
594 static HRESULT WINAPI xslprocessor_get_stylesheet(
595 IXSLProcessor *iface,
598 xslprocessor *This = impl_from_IXSLProcessor( iface );
600 FIXME("(%p)->(%p): stub\n", This, node);
604 static const struct IXSLProcessorVtbl xslprocessor_vtbl =
606 xslprocessor_QueryInterface,
608 xslprocessor_Release,
609 xslprocessor_GetTypeInfoCount,
610 xslprocessor_GetTypeInfo,
611 xslprocessor_GetIDsOfNames,
614 xslprocessor_put_input,
615 xslprocessor_get_input,
616 xslprocessor_get_ownerTemplate,
617 xslprocessor_setStartMode,
618 xslprocessor_get_startMode,
619 xslprocessor_get_startModeURI,
620 xslprocessor_put_output,
621 xslprocessor_get_output,
622 xslprocessor_transform,
624 xslprocessor_get_readyState,
625 xslprocessor_addParameter,
626 xslprocessor_addObject,
627 xslprocessor_get_stylesheet
630 HRESULT XSLProcessor_create(xsltemplate *template, IXSLProcessor **ppObj)
634 TRACE("(%p)\n", ppObj);
636 This = heap_alloc( sizeof (*This) );
638 return E_OUTOFMEMORY;
640 This->IXSLProcessor_iface.lpVtbl = &xslprocessor_vtbl;
644 This->stylesheet = template;
645 IXSLTemplate_AddRef(&template->IXSLTemplate_iface);
647 *ppObj = &This->IXSLProcessor_iface;
649 TRACE("returning iface %p\n", *ppObj);
656 HRESULT XSLTemplate_create(IUnknown *pUnkOuter, void **ppObj)
658 MESSAGE("This program tried to use a XSLTemplate object, but\n"
659 "libxml2 support was not present at compile time.\n");