summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/branches/sca-java-1.6/samples/domain-webapp/src/main/resources/webroot/index.html
blob: 425bd73734eda4867988d29bf5927be91745c640 (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
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
<html>
<!--
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.    
 -->
<head>
<title>Apache Tuscany Domain</TITLE>

    <script type="text/javascript" src="../SCADomain/scaDomain.js"></script>

    <script language="JavaScript">
    
       domainManager = new JSONRpcClient("../DomainManagerComponent/DomainManagerJson");

       function getNodeInfo() {
          domainManager.DomainManagerService.getNodeInfo(handleGetNodeInfo);
       }
       
       function handleGetNodeInfo(result) {
       
          var text = ""
          
          for (var i in result.list){
              var node = result.list[i];
              
              text = text + "<table>";
              text = text + "<TR CLASS='source_1' >";
              text = text + "  <TD>";
              text = text + "    <IMG SRC='node.png'/>&nbsp;&nbsp;" + node.domainUri;
              text = text + "  </TD>";
              
              var noProtocol = node.nodeManagerUrl.substring(7);
              var colonPos = noProtocol.indexOf(':')
              var nodeManagerWebUrl = noProtocol.substring(0, colonPos + 6);
              nodeManagerWebUrl = "http://" + nodeManagerWebUrl + "node/index.html";
              
              text = text + "  <TD CLASS='clickable link' ONCLICK=\"showNode('" + nodeManagerWebUrl + "')\">" + node.nodeUri + "</TD>";
              text = text + "</TR>";               
          }

          document.getElementById('domainInfo').innerHTML=text;
       }
       
        function showNode(url)
        {
            document.getElementById("nodePage").innerHTML="<IFRAME CLASS='alert_data' SRC='"+url+"'/>";
            window.location="#data";
            return;    
        }       

    </script>

    <link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body onload="getNodeInfo()">

<!--script type="text/javascript">
    
        // The proxy for the alert and alertsources services running in Tuscany
        var alertsService       = new dojo.rpc.JsonService("AlertsServiceJSONRPC?smd");
        var alertSourcesService = new dojo.rpc.JsonService("AlertsSourcesServiceJSONRPC?smd");

        // If you want to put an HTTP sniffer in the way to look at the JSONROPC packets you'll
        // need to edit the target address of the service in the smd. The only way to do this easily
        // is to read an smd from disc rather than generate one. There are two smds provided for this
	    //var alertsService       = new dojo.rpc.JsonService("service.smd");
        //var alertSourcesService = new dojo.rpc.JsonService("sources.smd");

        // The global list of alerts sources
        var alertSourceList = null;

        // The global list of alerts 
        var alertList       = null;

        // the constructor for entries on the alert source list
        function alertSourceType(name,id,address,feedAddress,feedType,popUsername,popPassword,popServer,lastChecked,javaClass) {
          this.name        = name;
          this.id          = id;
          this.address     = address;
          this.feedAddress = feedAddress;
          this.feedType    = feedType;
          this.lastChecked = lastChecked;
          this.javaClass   = "org.apache.tuscany.sca.demos.aggregator.types.impl.SourceTypeImpl";

        }

        function errorCallback(result, error, id) {
            var resultsNode = document.getElementById("errors");
            // There seems to be a problem somewhere as I should be able to get the error
            // details but all I can actually get is the Id from the error message
            // resultsNode.innerHTML = "there was an error! message id = "  + " error code = " + result.error.code + " error message = " + result.error.msg ;
           resultsNode.innerHTML = "An error was returned by the server. Message id = " +  result.id;
        }

        // Generate the alert sources table
        function getAlertSources()
        { 
            response = alertSourcesService.getAlertSources("Dojo");
            response.addCallbacks(getAlertSourcesCallback, errorCallback);

            getAlerts();
        }

        function getAlertSourcesCallback(result) {
            var resultsNode = document.getElementById("alertSourcesTable");
            if ( result.error != null ) {
                resultsNode.innerHTML = result.error;
            } else {
                // stash away the source list for when we come to edit it
                alertSourceList = result.source.list;

                // put out the html
                var text = ""
                var nextSourceId = 0
                for (var i in result.source.list){
                    var source = result.source.list[i];

                    text = text + "<table>";
                    text = text + "<TR CLASS='source_" + source.id + "' >";
                    text = text + "  <TD CLASS='source_name clickable' ONCLICK=\"displayAlert('" + source.address + "')\">";
                    text = text + "    <IMG SRC='rss.png'/>&nbsp;&nbsp;" + source.name;
                    text = text + "  </TD>";
                    text = text + "  <TD CLASS='clickable link' ONCLICK=\"showEditSource('" + source.id + "')\">Edit</TD>";
                    text = text + "  <TD CLASS='clickable link' ONCLICK=\"deleteSource('" + source.id + "')\">Delete</TD>";
                    text = text + "</TR>";
                    text = text + "<TR ID='edit_source_" + source.id + "' CLASS='hidden source_" + source.id + "'>";
                    text = text + "  <TD COLSPAN='3'>";
                    text = text + "    <TABLE CLASS='sourceDetailsTable'>";
                    text = text + "      <TR>";
                    text = text + "        <TD>Source name:</TD>";
                    text = text + "        <TD>";
                    text = text + "          <INPUT ID='source_" + source.id + "_name' TYPE='TEXT' SIZE='50' VALUE='" + source.name + "'/>";
                    text = text + "        </TD>";
                    text = text + "      </TR>";
                    text = text + "      <TR>";
                    text = text + "       <TD>Source address:</TD>"
                    text = text + "        <TD>";
                    text = text + "          <INPUT ID='source_" + source.id + "_address' TYPE='TEXT' SIZE='50' VALUE='" + source.address + "'/>";
                    text = text + "        </TD>";
                    text = text + "      </TR>";
                    text = text + "      <TR>";
                    text = text + "        <TD>";
                    text = text + "          <INPUT ID='source_" + source.id + "_type' TYPE='HIDDEN' VALUE='" + source.id + "'/>";
                    text = text + "          <INPUT TYPE='BUTTON' VALUE='Update' ONCLICK=\"updateSource('" + source.id + "')\"/>";
                    text = text + "          <INPUT TYPE='BUTTON' VALUE='Cancel' ONCLICK=\"hideEditSource('" + source.id + "')\"/>";
                    text = text + "        </TD>";
                    text = text + "      </TR>";
                    text = text + "    </TABLE>";
                    text = text + "  </TD>";
                    text = text + "</TR>";
               
                    nextSourceId = eval(source.id);
                }

                nextSourceId = nextSourceId + 1;

                text = text + "<TR CLASS='source_" + nextSourceId + "'>";
                text = text + "  <TD COLSPAN='4' CLASS='clickable link' ONCLICK=\"showAddNewSource('" + nextSourceId + "')\">Add new Alert Source</TD>";
                text = text + "</TR>";
                text = text + "<TR ID='add_source_" + nextSourceId + "' CLASS='hidden source_" + nextSourceId + "'>";
                text = text + "  <TD COLSPAN='4'>";
                text = text + "    <TABLE CLASS='sourceDetailsTable'>";
                text = text + "      <TR>";
                text = text + "        <TD>Source name:</TD>";
                text = text + "        <TD>";
                text = text + "          <INPUT ID='source_" + nextSourceId + "_name' TYPE='TEXT' SIZE='50'>";
                text = text + "        </TD>";
                text = text + "      </TR>";
                text = text + "      <TR>";
                text = text + "        <TD>Source address:</TD>";
                text = text + "        <TD>";
                text = text + "          <INPUT ID='source_" + nextSourceId + "_address' TYPE='TEXT' SIZE='50'>";
                text = text + "        </TD>";
                text = text + "      </TR>";
                text = text + "      <TR>";
                text = text + "        <TD>Source type:</TD>";
                text = text + "        <TD>";
                text = text + "          <SELECT ID='source_" + nextSourceId + "_type' ONCHANGE=\"showSourceType('" + nextSourceId + "')\">";
                text = text + "            <OPTION value='rss' selected='selected'>RSS/Atom feed</OPTION>";
                text = text + "          </SELECT>";
                text = text + "        </TD>";
                text = text + "      </TR>";
                text = text + "      <TR ID='add_rss_source'>";
                text = text + "        <TD COLSPAN='2'>";
                text = text + "          <TABLE CLASS='sourceDetailsTable'>";
                text = text + "            <TR>";
                text = text + "              <TD>Feed address:</TD>";
                text = text + "              <TD>";
                text = text + "                 <INPUT ID='source_" + nextSourceId + "_feedAddress' TYPE='TEXT' SIZE='50'/>";
                text = text + "              </TD>";
                text = text + "            </TR>";
                text = text + "          </TABLE>";
                text = text + "        </TD>";
                text = text + "      </TR>";
                text = text + "      <TR>";
                text = text + "        <TD>";
                text = text + "          <INPUT TYPE='BUTTON' VALUE='Add' ONCLICK=\"addSource('" + nextSourceId + "')\">";
                text = text + "          <INPUT TYPE='BUTTON' VALUE='Cancel' ONCLICK=\"hideAddNewSource('" + nextSourceId + "')\">";
                text = text + "        </TD>";
                text = text + "      </TR>";
                text = text + "    </TABLE>";
                text = text + "  </TD>";
                text = text + "</TR>";
                text = text + "</table>";

                resultsNode.innerHTML = text;  
            }
        }

        function showEditSource(sourceid)
        {
            document.getElementById("edit_source_"+sourceid).className = "source_"+sourceid;
        }

        function hideEditSource(sourceid)
        {
             document.getElementById("edit_source_"+sourceid).className = "hidden source_"+sourceid;
        }
 
        function updateSource(sourceid)
        {
            hideEditSource(sourceid);
            var source = getSource(sourceId);
            alertSourcesService.updateAlertSource(source);
            getAlertSources();
        }
 
        function deleteSource(sourceid)
        {
            alertSourcesService.removeAlertSource(sourceid);
            getAlertSources();
        }

        function showAddNewSource(sourceid)
        {
            document.getElementById("add_source_"+sourceid).className = "source_"+sourceid;
        }

        function hideAddNewSource(sourceid)
        {
            document.getElementById("add_source_"+sourceid).className = "hidden source_"+sourceid;
        }

        function addSource(sourceid)
        {
            hideAddNewSource(sourceid);
            var source = getSource(sourceid);
            alertSourcesService.addAlertSource(source); 

            // wait a little before getting the list back from the server
            setTimeout("getAlertSources()",1250);       
        }

        function getSource(sourceid)
        {
            var source = alertSourceList[sourceid];

            if ( source == null ){
                source = new alertSourceType("name","id","address","feedAddress","feedType","popUsername","popPassword","popServer","lastChecked","javaClass");
                alertSourceList[sourceid] = source;
            }
            
            source.name     = document.getElementById("source_"+sourceid+"_name").value;
            source.id       = sourceid;
            source.address  = document.getElementById("source_"+sourceid+"_address").value;
            var typeElem    = document.getElementById("source_"+sourceid+"_type");
            source.feedType = typeElem.options[typeElem.selectedIndex].value; 

            if(source.feedType=="rss")
            {
                source.feedAddress = document.getElementById("source_"+sourceid+"_feedAddress").value;
                
            }
            else if(source.feedType=="pop")
            {
                source.popServer   = document.getElementById("source_"+sourceid+"_popServer").value;
                source.popUsername = document.getElementById("source_"+sourceid+"_popUsername").value;
                source.popPassword = document.getElementById("source_"+sourceid+"_popPassword").value;
            } 
            return source;     
        }

        // Generate the alerts table
        function getAlerts()
        { 
            response = alertsService.getAllNewAlerts("Dojo");
            response.addCallbacks(getAlertsCallback, errorCallback);
        }

        function getAlertsCallback(result) {
            var resultsNode = document.getElementById("alertsTable");
            if ( result.error != null ) {
                resultsNode.innerHTML = result.error;
            } else {
                alertList = result.alert.list;
                var text = ""
                for (var i in result.alert.list){
                    var alert = result.alert.list[i];

                    text = text + "<table>";
                    text = text + "<TR class='source_" + alert.sourceId + " clickable' onclick=\"displayAlert('" + alert.address + "')\">";
                    text = text + " <TD class='alert_text'>";
                    text = text + "   <SPAN id='" + alert.id + "' class='unread_title'>" + alert.title + "</SPAN>";
                    text = text + "   <SPAN class='summary'> - " + alert.summary.substring(0, 80)  + "...</SPAN>";
                    text = text + " </TD>";
                    text = text + " <TD>";
                    text = text +     alert.date;
                    text = text + "  </TD>"
                    text = text + "</TR>"
                    text = text + "</table>";
                }

                resultsNode.innerHTML = text;  
            }
        }



        function displayAlert(url)
        {
            document.getElementById("alertData").innerHTML="<IFRAME CLASS='alert_data' SRC='"+url+"'/>";
            window.location="#data";
            return;    
        }
</script-->

<h1 id="top">Apache Tuscany Domain</h1>
<div id="errors"></div>

<p>Domain Name<span id="domainName"></span>:</p>

<div id="domainInfo"></div>

<p /><input type="button" value="Refresh" onclick="getNodeInfo()" />

<div id="nodePage"></div>

</body>
</html>