forked from DNNCommunity/DNN.IFrame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controller.vb
254 lines (209 loc) · 10.4 KB
/
Controller.vb
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
'
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2005
' by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
'
Imports DotNetNuke.Modules.IFrame.Domain
Imports DotNetNuke.Modules.IFrame.Data
Imports DotNetNuke.Entities.Modules
Imports System.Xml
Namespace DotNetNuke.Modules.IFrame
''' <summary>
''' IFrame Module controller.
''' </summary>
Public Class Controller
Implements IPortable
#Region "| Fields |"
Protected Const RootElement As String = "iframe"
Protected Const ParameterGroupElement As String = "parameters"
Protected Const ParameterElement As String = "param"
Protected Const ParameterNameElement As String = "name"
Protected Const ParameterTypeElement As String = "type"
Protected Const ParameterArgumentElement As String = "argument"
Private _dataProvider As DataProvider
#End Region
#Region "| Sub-Classes |"
''' <summary>
''' IFrame Module properties.
''' </summary>
''' <remarks>
''' All properties will be used as <c>iframe</c> tag attributes unless preceded by the
''' NotAnAttributePrefix value.
''' </remarks>
Public Class Properties
Public Const NotAnAttributePrefix As String = "x-"
'Public Const UrlParameter As String = "x-url" 'removed!
Public Const Name As String = "name"
Public Const Source As String = "src"
Public Const SourceType As String = NotAnAttributePrefix + "src-type"
Public Const Height As String = "height"
Public Const Autoheight As String = NotAnAttributePrefix + "autoheight"
Public Const Width As String = "width"
Public Const CssStyle As String = "style"
Public Const OnLoad As String = "onload"
Public Const ToolTip As String = "title"
Public Const Scrolling As String = "scrolling"
Public Const Border As String = "frameborder"
Public Const AllowTransparency As String = "allowtransparency"
Public Const UseAsHash As String = NotAnAttributePrefix + "use-as-hash"
End Class
#End Region
#Region "| Import/Export |"
''' <summary>
''' Exports module settings.
''' </summary>
''' <param name="ModuleID">Unique identifier of the module to be exported.</param>
Public Function ExportModule(ByVal ModuleID As Integer) As String Implements IPortable.ExportModule
' constants
Const StartTagFormat As String = "<{0}>"
Const EndTagFormat As String = "</{0}>"
Const TagFormat As String = "<{0}>{1}</{0}>"
' init vars
Dim objController As New ModuleController
Dim objSettings As Hashtable = objController.GetModuleSettings(ModuleID)
Dim sbXml As New StringBuilder
Dim colParameters As IFrameParameterCollection
' start xml
sbXml.AppendFormat(StartTagFormat, RootElement)
' save all keys
For Each key As Object In objSettings.Keys
sbXml.AppendFormat(TagFormat, Convert.ToString(key), _
XmlUtils.XMLEncode(Convert.ToString(objSettings(key))))
Next
' save all parameters
sbXml.AppendFormat(StartTagFormat, ParameterGroupElement)
colParameters = GetParameters(ModuleID)
For i As Integer = 0 To colParameters.Count - 1
If colParameters(i).IsValid Then
sbXml.AppendFormat(StartTagFormat, ParameterElement)
sbXml.AppendFormat(TagFormat, ParameterNameElement, XmlUtils.XMLEncode(colParameters(i).Name))
sbXml.AppendFormat(TagFormat, ParameterTypeElement, _
XmlUtils.XMLEncode( _
[Enum].GetName(colParameters(i).Type.GetType(), _
colParameters(i).Type)))
If colParameters(i).IsArgumentRequired Then _
sbXml.AppendFormat(TagFormat, ParameterArgumentElement, _
XmlUtils.XMLEncode(colParameters(i).TypeArgument))
sbXml.AppendFormat(EndTagFormat, ParameterElement)
End If
Next
sbXml.AppendFormat(EndTagFormat, ParameterGroupElement)
' end xml
sbXml.AppendFormat(EndTagFormat, RootElement)
' return xml
Return sbXml.ToString()
End Function
''' <summary>
''' Imports module settings.
''' </summary>
''' <param name="ModuleID">Unique identifier of the module to be exported.</param>
''' <param name="Content">XML content to import.</param>
''' <param name="Version">Version of the content being imported.</param>
''' <param name="UserID">Unique identifier of the user importing the content.</param>
Public Sub ImportModule(ByVal ModuleID As Integer, ByVal Content As String, ByVal Version As String, _
ByVal UserID As Integer) Implements IPortable.ImportModule
' init vars
Dim objController As New ModuleController
Dim objXml As XmlNode = GetContent(Content, RootElement)
' update settings
For i As Integer = 0 To objXml.ChildNodes.Count - 1
' init vars
Dim objNode As XmlNode = objXml.ChildNodes(i)
Dim strKey As String = objNode.LocalName
' if not parameters node, save setting; otherwise, add to data store
If strKey <> ParameterGroupElement Then
' handle version conflicts
Select Case Version
Case "03.02.00"
Case Else
If strKey = "border" Then strKey = Properties.Border
End Select
' update settings
objController.UpdateModuleSetting(ModuleID, strKey, objNode.InnerText)
Else
' loop thru parameters
For j As Integer = 0 To objNode.ChildNodes.Count - 1
Dim objParam As New IFrameParameter
objParam.ModuleID = ModuleID
For k As Integer = 0 To objNode.ChildNodes(j).ChildNodes.Count - 1
Dim objParamPropertyNode As XmlNode = objNode.ChildNodes(j).ChildNodes(k)
Select Case objParamPropertyNode.LocalName
Case ParameterNameElement
objParam.Name = objParamPropertyNode.InnerText
Case ParameterTypeElement
objParam.Type = IFrameParameter.ParseType(objParamPropertyNode.InnerText)
Case ParameterArgumentElement
objParam.TypeArgument = objParamPropertyNode.InnerText
End Select
Next
' add param
If objParam.IsValid Then AddParameter(objParam)
Next
End If
Next
End Sub
#End Region
#Region "| Data Access |"
''' <summary>
''' Gets the single instance of the current <see cref="DataProvider"/>.
''' </summary>
Protected ReadOnly Property DataProvider() As DataProvider
Get
If Me._dataProvider Is Nothing Then
Me._dataProvider = DataProvider.Instance
End If
Return Me._dataProvider
End Get
End Property
''' <summary>
''' Creates a new object in the data store.
''' </summary>
''' <param name="Parameter">Parameter object.</param>
Public Sub AddParameter(ByVal Parameter As IFrameParameter)
DataProvider.AddParameter(Parameter)
End Sub
''' <summary>
''' Retrieves an existing object from the data store.
''' </summary>
''' <param name="Key">Parameter identifier.</param>
Public Function GetParameter(ByVal Key As IFrameParameter.UniqueKey) As IFrameParameter
Return DataProvider.GetParameter(Key)
End Function
''' <summary>
''' Retrieves a collection of objects from the data store.
''' </summary>
''' <param name="ModuleID">Module identifier.</param>
Public Function GetParameters(ByVal ModuleID As Integer) As IFrameParameterCollection
Return DataProvider.GetParameters(ModuleID)
End Function
''' <summary>
''' Updates an existing object in the data store.
''' </summary>
''' <param name="Parameter">Parameter object.</param>
Public Sub UpdateParameter(ByVal Parameter As IFrameParameter)
DataProvider.UpdateParameter(Parameter)
End Sub
''' <summary>
''' Removes an existing object from the data store.
''' </summary>
''' <param name="Key">Parameter identifier.</param>
Public Sub DeleteParameter(ByVal Key As IFrameParameter.UniqueKey)
DataProvider.DeleteParameter(Key)
End Sub
#End Region
End Class
End Namespace