summaryrefslogtreecommitdiffstats
path: root/idle-inhibit/tools/spec-to-introspect.xsl
blob: 24682371e7096303431147a9d4fb330760353454 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"
        exclude-result-prefixes="tp">

<!--
    Telepathy D-Bus Introspection to EggDBus Introspection format translator.

    Copyright 2009  Michael Leupold <lemma@confuego.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-->

<!--
    TODO:
     - Enable conversion of dictionary element types (eg. "{ss}") and
       struct types (eg. "(sayay)")
     - unhandled: tp:simple-type, tp:enum, tp:flags, tp:external-type
     - tp:docstring may contain XHTML which this template doesn't handle
-->

    <xsl:include href="resolve-type.xsl"/>

    <!-- main template -->
    <xsl:template match="tp:spec">
        <node>
            <xsl:apply-templates select="tp:errors"/>
            <xsl:apply-templates select="tp:struct"/>
            <!-- TODO: <xsl:apply-templates select="tp:mapping"/> -->
            <xsl:apply-templates select="node/interface"/>
        </node>
    </xsl:template>

    <!-- handle most of the D-Bus introspection elements -->
    <xsl:template match="interface|annotation|method|signal">
        <xsl:copy>
            <xsl:for-each select="@*">
                <xsl:if test="not(starts-with(name(), 'tp:'))">
                    <xsl:copy/>
                </xsl:if>
            </xsl:for-each>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

    <!-- handle the arg and property D-Bus introspection elements.
         They get special handling because they may contain a tp:type
         attribute -->
    <xsl:template match="arg|property">
        <xsl:copy>
            <xsl:for-each select="@*">
                <xsl:if test="not(starts-with(name(), 'tp:'))">
                    <xsl:copy/>
                </xsl:if>
            </xsl:for-each>
            <xsl:for-each select="@tp:type">
                <xsl:variable name="type">
                    <xsl:call-template name="TpType">
                        <xsl:with-param name="type" select="."/>
                    </xsl:call-template>
                </xsl:variable>
                <annotation name="org.gtk.EggDBus.Type">
                    <xsl:attribute name="value">
                        <xsl:value-of select="translate(translate($type, ' ', ''), '&#xa;', '')"/>
                    </xsl:attribute>
                </annotation>
            </xsl:for-each>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

    <!-- tp:docstring to org.gtk.EggDBus.DocString -->
    <xsl:template match="tp:docstring">
        <annotation name="org.gtk.EggDBus.DocString">
            <xsl:attribute name="value">
                <xsl:value-of select="normalize-space(text())"/>
            </xsl:attribute>
        </annotation>
    </xsl:template>

    <!-- tp:errors to org.gtk.EggDBus.DeclareErrorDomain -->
    <xsl:template match="tp:errors">
        <annotation value="Error" name="org.gtk.EggDBus.DeclareErrorDomain">
            <xsl:apply-templates select="tp:docstring"/>
            <xsl:apply-templates select="tp:error"/>
        </annotation>
    </xsl:template>

    <!-- tp:error to org.gtk.EggDBus.ErrorDomain.Member -->
    <xsl:template match="tp:error">
        <annotation name="org.gtk.EggDBus.ErrorDomain.Member">
            <xsl:attribute name="value">
                <xsl:value-of select="concat(../@namespace, '.', @name)"/>
            </xsl:attribute>
            <xsl:apply-templates select="tp:docstring"/>
        </annotation>
    </xsl:template>

    <!-- tp:struct to org.gtk.EggDBus.DeclareStruct -->
    <xsl:template match="tp:struct">
        <annotation name="org.gtk.EggDBus.DeclareStruct">
            <xsl:attribute name="value">
                <xsl:value-of select="@name"/>
            </xsl:attribute>
            <xsl:apply-templates select="tp:docstring"/>
            <xsl:apply-templates select="tp:member"/>
        </annotation>
    </xsl:template>

    <!-- tp:member to org.gtk.EggDBus.Struct.Member -->
    <xsl:template match="tp:member">
        <xsl:variable name="type">
            <xsl:call-template name="ResolveType">
                <xsl:with-param name="node" select="."/>
            </xsl:call-template>
        </xsl:variable>
        <annotation name="org.gtk.EggDBus.Struct.Member">
            <xsl:attribute name="value">
                <xsl:value-of select="concat(normalize-space($type), ':', @name)"/>
            </xsl:attribute>
            <xsl:apply-templates select="tp:docstring"/>
        </annotation>
    </xsl:template>

    <xsl:template match="text()"/>

    <xsl:output method="xml" indent="yes" encoding="UTF-8"
                omit-xml-declaration="no"
                doctype-system="http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"
                doctype-public="-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"/>

</xsl:stylesheet>