forked from googlearchive/gsa-admin-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteractive-feed-client.html
executable file
·444 lines (439 loc) · 13.8 KB
/
interactive-feed-client.html
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Interactive Feed Client</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<style>
body {
font-family: arial, sans-serif;
background-color:#fff;
font-size: small;
margin: 24px 8px 8px;
color:#000;
}
#header {
position: relative;
height:50px;
margin:0 0 11px;
}
#logo { /* in header */
float:left;
width: 175px;
top:-5px;
left:0;
padding:0;
margin:0;
position:absolute;
}
#hints { /* in header */
margin:5px 0 0 174px;
padding:1px 0 1px 3px;
}
h1, h2, h3, h4, h5 {
font-weight:bold;
margin-bottom:0;
}
h1 {
font-size:large;
font-weight:bold;
border-top: 1px solid;
background-color: #e5ecf9;
border-color: #3366CC;
margin:5px 0 0 174px;
padding:1px 0 1px 3px;
}
h2 {
font-size:120%;
margin-top:1.5em;
border-bottom: 1px solid;
border-color: #3366CC;
}
h3 {
font-size:110%;
margin-top:.7em;
left:0;
top:.7em;
}
td {
vertical-align:top;
}
form {
margin:0;
padding0;
}
</style>
<script>
function parseXML() {
var feedPreview = document.previewfeed.feed.value;
feedPreview = feedPreview.replace(/<!DOCTYPE gsafeed PUBLIC "-\/\/Google\/\/DTD GSA Feeds\/\/EN" "">/, ""); // removing the DOCTYPE since MSIE has problems with that.
try { // Internet Explorer
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.loadXML(feedPreview);
} catch (e) {
try { // Firefox, Mozilla, Opera, etc.
parser = new DOMParser();
xmlDoc = parser.parseFromString(feedPreview, "text/xml");
} catch (e) {
alert(e.message);
return;
}
}
var newRecord = xmlDoc.createElement("record");
if ((document.record.url.value.indexOf("https://") == 0) ||
(document.record.url.value.indexOf("http://") == 0) ||
(document.record.url.value.indexOf("unc:\\") == 0) ||
(document.record.url.value.indexOf("smb:") == 0)) {
newAttribute = xmlDoc.createAttribute("url");
newAttribute.value = document.record.url.value;
newRecord.setAttributeNode(newAttribute);
} else {
alert("Error: Can not update the preview since the field 'The record's URL' contains no valid URL.");
return;
}
var newAttribute = null;
newAttribute = xmlDoc.createAttribute("mimetype");
newAttribute.value = document.record.mimetype.value;
newRecord.setAttributeNode(newAttribute);
if (document.record.displayurl.value != "") {
newAttribute = xmlDoc.createAttribute("displayurl");
newAttribute.value = document.record.displayurl.value;
newRecord.setAttributeNode(newAttribute);
}
if (document.record.action.value != "") {
newAttribute = xmlDoc.createAttribute("action");
newAttribute.value = document.record.action.value;
newRecord.setAttributeNode(newAttribute);
}
if (document.record.authmethod.value != "") {
newAttribute = xmlDoc.createAttribute("authmethod");
newAttribute.value = document.record.authmethod.value;
newRecord.setAttributeNode(newAttribute);
}
if ((document.record.name1.value != "") && (document.record.content1.value != "") || (document.record.name2.value != "") && (document.record.content2.value != "") || (document.record.name3.value != "") && (document.record.content3.value != "")) {
var newMetadata = xmlDoc.createElement('metadata');
newRecord.appendChild(newMetadata);
if ((document.record.name1.value != "") && (document.record.content1.value != "")) {
newMeta = xmlDoc.createElement('meta');
newMetadata.appendChild(newMeta);
newAttribute = xmlDoc.createAttribute("name");
newAttribute.value = document.record.name1.value;
newMeta.setAttributeNode(newAttribute);
newAttribute = xmlDoc.createAttribute("content");
newAttribute.value = document.record.content1.value;
newMeta.setAttributeNode(newAttribute);
}
if ((document.record.name2.value != "") && (document.record.content2.value != "")) {
newMeta = xmlDoc.createElement('meta');
newMetadata.appendChild(newMeta);
newAttribute = xmlDoc.createAttribute("name");
newAttribute.value = document.record.name2.value;
newMeta.setAttributeNode(newAttribute);
newAttribute = xmlDoc.createAttribute("content");
newAttribute.value = document.record.content2.value;
newMeta.setAttributeNode(newAttribute);
}
if ((document.record.name3.value != "") && (document.record.content3.value != "")) {
newMeta = xmlDoc.createElement('meta');
newMetadata.appendChild(newMeta);
newAttribute = xmlDoc.createAttribute("name");
newAttribute.value = document.record.name3.value;
newMeta.setAttributeNode(newAttribute);
newAttribute = xmlDoc.createAttribute("content");
newAttribute.value = document.record.content3.value;
newMeta.setAttributeNode(newAttribute);
}
}
if (document.record.content.value != "") {
var newContent = xmlDoc.createElement('content');
if (document.record.base64.checked) {
newAttribute = xmlDoc.createAttribute("encoding");
newAttribute.value = "base64binary";
newContent.setAttributeNode(newAttribute);
}
if ((document.record.mimetype.value == "text/html") || (document.record.mimetype.value == "text/xml")) {
var newContentText = xmlDoc.createCDATASection(document.record.content.value);
} else {
var newContentText = xmlDoc.createTextNode(document.record.content.value);
}
newContent.appendChild(newContentText);
newRecord.appendChild(newContent);
}
group = xmlDoc.getElementsByTagName("group")[0];
try {
group.insertBefore(newRecord, group.firstChild);
} catch (e) {
//alert(e.message);
alert("Error: Can not update the preview since the preview area seems to contain not-wellformed XML code and thus can not be updated.");
return;
}
document.previewfeed.feed.value = '<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE gsafeed PUBLIC "-//Google//DTD GSA Feeds//EN" "">\n';
document.previewfeed.feed.value += nodeToString(xmlDoc.getElementsByTagName("gsafeed")[0], 0);
}
function nodeToString(node, indentLevel) {
var theString = "";
var noWhiteSpace = "";
var withIndent = true;
var textNodeValue = "";
theString += insertTabs(indentLevel);
theString += '<' + node.nodeName;
for (var i = 0; i < node.attributes.length; i++) {
theString += ' ' + node.attributes[i].nodeName + '="' + xmlify(node.attributes[i].nodeValue) + '"';
}
if (node.hasChildNodes()) {
theString += '>';
if ((node.childNodes[0].nodeType == 3) || (node.childNodes[0].nodeType == 4)) {
noWhiteSpace = node.childNodes[0].nodeValue;
noWhiteSpace = noWhiteSpace.replace(/\s/g, "");
}
if ((node.childNodes[0].nodeType == 3) && (noWhiteSpace != "")) {
theString += xmlify(node.childNodes[0].nodeValue);
withIndent = false;
} else {
if ((node.childNodes[0].nodeType == 4) && (noWhiteSpace != "")) {
theString += "<![CDATA[" + node.childNodes[0].nodeValue + "]]>";
withIndent = false;
} else {
theString += '\n';
}
}
for (var i = 0; i < node.childNodes.length; i++) {
if (node.childNodes[i].nodeType == 1) {
theString += nodeToString(node.childNodes[i], indentLevel + 1);
}
}
if (withIndent) {
theString += insertTabs(indentLevel);
}
theString += '</' + node.nodeName + '>\n';
} else {
theString += '/>\n';
}
withIndent = true;
return theString;
}
function submitFeed() {
response.location.href = "about:blank";
if ((document.submitfeed.datasource.value.search(/\W/) != -1) || (document.submitfeed.datasource.value.search(/_/) != -1)) {
alert("Error: Can not submit the feed since the field 'Name of Data Source' must contain only alphanumeric characters.");
return;
}
document.submitfeed.data.value = document.previewfeed.feed.value;
//alert(document.submitfeed.data.value);
document.getElementById("submitfeed").action = document.submitfeed.gsaurl.value;
try { // Firefox, Mozilla, Opera, etc.
document.submitfeed.submit();
} catch (e) {
alert(e.message);
return;
}
}
function insertTabs(amount) {
var tabString = "";
for (var j = 0; j < amount; j++) {
tabString += "\t";
}
return tabString;
}
function xmlify(textNodeValue) {
textNodeValue = textNodeValue.replace(/</g, "<");
textNodeValue = textNodeValue.replace(/>/g, ">");
textNodeValue = textNodeValue.replace(/&/g, "&");
textNodeValue = textNodeValue.replace(/"/g, """);
textNodeValue = textNodeValue.replace(/'/g, "'");
return textNodeValue;
}
</script>
</head>
<body>
<div id="header">
<h1 id="doc_title">Interactive Feed Client for the Google Search Appliance</h1>
<div id="hints">The interactive feed client is designed for making experiments with your GSA and XML feeds. It provides a straightforward way to get familiar with XML feeds.</div>
<div id="hints">Please read the <a href="http://www.google.com/support/enterprise/static/gsa/docs/admin/72/gsa_doc_set/feedsguide/feedsguide.html" target="_blank">Feed Protocol Developer's Guide</a> to learn more about the options and capabilities of feeds.</div>
</div>
<table border="0" width="100%" cellpadding="15">
<tr>
<td valign="top" width="20%">
<form name="record" action="">
<h2>1. Define a Record</h2>
<table border="0">
<tr>
<td style="white-space:nowrap;color:#c00;">
The record's URL *
</td>
<td>
<input size="60" type="text" name="url" value="">
</td>
</tr>
<tr>
<td style="white-space:nowrap;color:#c00;">
Mime-type *<br>
<span style="font-size:10px;color:#000;">(mandatory but ignored for web<br>and metadata-and-url feeds)</span>
</td>
<td>
<select name="mimetype" style="width:150px">
<option value="text/plain">text/plain</option>
<option value="text/html">text/html</option>
<option value="text/xml">text/xml</option>
<option value="text/comma-separated-values">text/comma-separated-values</option>
</select>
</td>
</tr>
<tr>
<td style="white-space:nowrap;">
Displayed URL
</td>
<td>
<input size="60" type="text" name="displayurl" value="">
</td>
</tr>
<tr>
<td>
Action<br>
<span style="font-size:10px;color:#000;">(applies for content feeds only)</span>
</td>
<td>
<select name="action" style="width:150px">
<option value="">default (Add)</option>
<option value="add">Add</option>
<option value="delete">Delete</option>
</select>
</td>
</tr>
<tr>
<td style="white-space:nowrap;">
Authentication Method<br>
<span style="font-size:10px;color:#000;">(applies for content feeds only)</span>
</td>
<td>
<select name="authmethod" style="width:150px">
<option value="">default (none)</option>
<option value="httpbasic">httpbasic</option>
<option value="ntlm">NTLM</option>
<option value="httpsso">httpsso</option>
</select>
</td>
</tr>
<tr>
<td valign="top">
Metadata
</td>
<td>
<table border="0">
<tr>
<td>Name</td><td>Content</td>
</tr>
<tr>
<td><input size="10" type="text" name="name1" value=""> =</td>
<td><input size="30" type="text" name="content1" value=""></td>
</tr>
<tr>
<td><input size="10" type="text" name="name2" value=""> =</td>
<td><input size="30" type="text" name="content2" value=""></td>
</tr>
<tr>
<td><input size="10" type="text" name="name3" value=""> =</td>
<td><input size="30" type="text" name="content3" value=""></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
Content
</td>
<td>
<textarea name="content" wrap="virtual" rows="5" style="width: 100%"></textarea>
<br/>
<input type="checkbox" name="base64" value="base64"> This content is Base64 encoded
</td>
</tr>
</table>
<p align="right">
<input type="button" value="Add Record to the Feed Preview >" onClick ="parseXML();return null;">
</p>
</form>
</td>
<td valign="top">
<form name="previewfeed">
<h2>2. Preview the Feed</h2><br>
<textarea name="feed" wrap="off" rows="25" style="width: 100%">
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE gsafeed PUBLIC "-//Google//DTD GSA Feeds//EN" "">
<gsafeed>
<header>
<datasource>web</datasource> <!-- (this value will currently be ignored) -->
<feedtype>full</feedtype> <!-- (this value will currently be ignored) -->
</header>
<group>
</group>
</gsafeed>
</textarea>
</form>
</td>
</tr>
<tr>
<td valign="top">
<form id="submitfeed" name="submitfeed" enctype="multipart/form-data" method="POST" action="" target="response">
<h2>3. Submit the Feed</h2>
<table border="0">
<tr>
<td style="white-space:nowrap;color:#c00;">
Name of Data Source *
</td>
<td>
<input size="10" type="text" name="datasource" value="test">
</td>
</tr>
<tr>
<td style="white-space:nowrap;color:#c00;">
Type of Feed *
</td>
<td>
<select name="feedtype" style="width:150px">
<option value="full">Full</option>
<option value="incremental">Incremental</option>
<option value="metadata-and-url">Metadata and URL</option>
</select>
</td>
</tr>
<tr>
<td>
URL to Submit Feeds
</td>
<td>
<span style="border-top:3px #ccc groove;border-bottom:3px #ccc groove;padding:1px;border-left:3px #ccc groove;padding:1px;">http://</span>
<input style="border-top:3px #ccc groove;border-bottom:3px #ccc groove;padding:1px;border-left:0px;border-right:0px;width:auto;" size="20" type="text" name="gsaurl" value="gsa.yourdomain.com" target="_blank">
<span style="border-top:3px #ccc groove;border-bottom:3px #ccc groove;padding:1px;border-right:3px #ccc groove;">:19900/xmlfeed</span>
</td>
</tr>
</table>
<input type="hidden" name="data">
<p align="right">
<input onClick="submitFeed();return null;" onblur="document.getElementById('response').src='about:blank'" type="button" value="Submit the Feed">
</p>
</form>
</td>
<td valign="top">
<h2>4. Check the Server Response</h2>
<iframe src="about:blank" name="response" id="response" width="100%" height="100" align="left" scrolling="yes" marginheight="0" marginwidth="0" frameborder="0"></iframe>
</td>
</tr>
</table>
<hr noshade>
<pre>
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This utility is not supported by Google
# Author: Alex Kerschhofer
</pre>
</body>
</html>