You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by aj...@apache.org on 2007/02/08 01:56:03 UTC
svn commit: r504759 - in /incubator/tuscany/cpp/sca/samples/AlertAggregator:
sample.alerter/ sample.display/
Author: ajborley
Date: Wed Feb 7 16:56:02 2007
New Revision: 504759
URL: http://svn.apache.org/viewvc?view=rev&rev=504759
Log:
Added Alert Aggregator sample requires Python & REST extensions and Python feedparser library from http://feedparser.org
Added:
incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/Makefile.am (with props)
incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/POPCheckerImpl.py (with props)
incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/POPCheckerImpl.rb (with props)
incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/RSSCheckerImpl.py (with props)
incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/sample.alerter.composite (with props)
incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/
incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/Alerter.xsd (with props)
incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/HTMLDisplayImpl.py (with props)
incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/Makefile.am (with props)
incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/sample.display.composite (with props)
Added: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/Makefile.am?view=auto&rev=504759
==============================================================================
--- incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/Makefile.am (added)
+++ incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/Makefile.am Wed Feb 7 16:56:02 2007
@@ -0,0 +1,23 @@
+# 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.
+
+deploydir=$(prefix)/samples/AlertAggregator/deploy
+compositedir=$(deploydir)/sample.alerter
+
+composite_DATA = *.composite *.py *.rb *.xsd
+EXTRA_DIST = *.composite *.py *.rb *.xsd
+
Propchange: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/Makefile.am
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/Makefile.am
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/POPCheckerImpl.py
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/POPCheckerImpl.py?view=auto&rev=504759
==============================================================================
--- incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/POPCheckerImpl.py (added)
+++ incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/POPCheckerImpl.py Wed Feb 7 16:56:02 2007
@@ -0,0 +1,104 @@
+# 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.
+#
+
+import poplib, email, datetime, re, xml.etree.ElementTree
+
+def getNewAlerts(popserver, username, password, lastchecktimestamp):
+
+ print "POPCheckerImpl getting new POP e-mail alerts\n"
+
+ alertsXML = "<alerts xmlns=\"http://tuscany.apache.org/samples/alerter\">\n"
+
+ # initially set lastchecked to the epoch before trying to use the lastchecked string
+ lastcheckdate = datetime.datetime.min
+ if lastchecktimestamp:
+ lastcheckdate = datetime.datetime.strptime(lastchecktimestamp, "%Y-%m-%dT%H:%M:%S")
+
+ numberOfNewEmails = 0
+
+ mail = poplib.POP3(popserver)
+ mail.user(username)
+ mail.pass_(password)
+ msgCount, inboxSize = mail.stat()
+
+ for msgNum in range(msgCount):
+
+ print "getting msg", msgNum+1, "of", msgCount
+
+ data = ""
+ for line in mail.retr(msgNum+1)[1]:
+ data += str(line)
+ data += "\n"
+
+ msg = email.message_from_string(data)
+
+ # date is of form "Sun, 21 Jan 2007 13:51:53 -0500"
+ msgDateString = msg.get("Date")
+ msgDateString, tz = msgDateString.rsplit(None, 1)
+
+ timezoneadjust = datetime.timedelta(0, (int(tz)/100)*60*60 + int(tz[3:5])*60)
+
+ msgdate = datetime.datetime.strptime(msgDateString, "%a, %d %b %Y %H:%M:%S") + timezoneadjust
+
+ if msgdate >= lastcheckdate:
+ msgTo = msg.get("To")
+ msgFrom = msg.get("From")
+ msgSubject = msg.get("Subject")
+
+ msgBody = ""
+ if msg.is_multipart():
+ for msgPart in msg.get_payload():
+ if msgPart.get_content_type() == "text/plain" or (msgPart.get_content_type() == "text/html" and msgBody == ""):
+ msgBody = msgPart.get_payload()
+ else:
+ msgBody = msg.get_payload()
+
+ alertsXML += "<alert><title>" + encodeXML(msgFrom) + " - "+encodeXML(msgSubject)+"</title>\n"
+ alertsXML += "<address></address>\n"
+ alertsXML += "<date>" + msgdate.isoformat() + "</date>\n"
+ alertsXML += "<summary>From: " + encodeXML(msgFrom)
+ alertsXML += "\nTo: "+encodeXML(msgTo)
+ alertsXML += "\nSubject: "+encodeXML(msgSubject)
+ alertsXML += "\nDate: " + msgdate.isoformat()
+ alertsXML += "\n\n" + stripXML(msgBody) + "</summary></alert>\n"
+
+
+ mail.quit()
+
+ alertsXML += "</alerts>"
+
+ return xml.etree.ElementTree.XML(alertsXML)
+
+
+def encodeXML(data):
+ data = re.sub("<","[", data)
+ data = re.sub(">","]", data)
+ return data
+
+def stripXML(data):
+ elementsRemoved = re.sub("<.*?>","", data)
+ entitiesRemoved = re.sub("&.*?;", " ", elementsRemoved)
+ asciiEncoded = entitiesRemoved.encode('ASCII', 'replace')
+ returnData = asciiEncoded.replace('&', 'and')
+ return returnData
+
+
+
+# Testing
+
+# print getNewAlerts("mail.eclipse.co.uk", "andrew@borley-hall.eclipse.co.uk", "app73sauc3", "2007-01-29T02:15:53")
Propchange: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/POPCheckerImpl.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/POPCheckerImpl.py
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/POPCheckerImpl.rb
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/POPCheckerImpl.rb?view=auto&rev=504759
==============================================================================
--- incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/POPCheckerImpl.rb (added)
+++ incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/POPCheckerImpl.rb Wed Feb 7 16:56:02 2007
@@ -0,0 +1,122 @@
+# 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.
+#
+
+require 'net/pop'
+require "rexml/document"
+include REXML
+
+# class POPChecker
+#
+# def initialize()
+# print "POPCheckerImpl.initialize\n"
+# end
+
+def getNewAlerts(popserver, username, password, lastchecked)
+
+ print "POPCheckerImpl getting new POP e-mail alerts\n"
+
+ alertsXML = "<alerts xmlns=\"http://tuscany.apache.org/samples/alerter\">\n"
+
+ # initially set lastchecked to the epoch before trying to use the lastchecked string
+ lastcheckedtime = Time.at(0)
+ if lastchecked != ''
+ # lastchecked (if provided) is of form 2007-02-17T23:34:56
+ year , month, day, hour, min, sec = lastchecked.split(/[-T:]/)
+ lastcheckedtime = Time.gm(year , month, day, hour, min, sec, nil)
+ end
+
+ numberOfEmails = 0
+
+ Net::POP3.start(popserver, 110, username, password) do |pop|
+
+ if !pop.mails.empty?
+ pop.each_mail do |m|
+ msg = m.pop
+
+ header, body = msg.split("\r\n\r\n", 2)
+ date = getMessageField("Date", header)
+ # date is of form "Sun, 21 Jan 2007 13:51:53 -0500"
+ parts = date.split(' ')
+ timeparts = parts[4].split(':')
+ timezoneSecs = (parts[5].to_i()/100)*60*60 + (parts[5].slice(-2,0).to_i())*60
+
+ msgtime = Time.gm(timeparts[2], timeparts[1], timeparts[0], parts[1], parts[2], parts[3], nil, nil, nil, nil) + timezoneSecs
+
+
+ if msgtime >= lastcheckedtime
+ from = getMessageField("From", header)
+ subject = getMessageField("Subject", header)
+
+ alertsXML += "<alert><title>From: " + encodeXML(from) + "\nSubject: "+encodeXML(subject)+"</title>\n"
+ alertsXML += "<address></address>\n"
+ alertsXML += "<date>" + msgtime.strftime("%Y-%m-%dT%H:%M:%S") + "</date>\n"
+ alertsXML += "<summary>" + stripXML(body) + "</summary></alert>\n"
+
+ numberOfEmails += 1
+ end
+
+ end
+ end
+ end
+ alertsXML += "</alerts>"
+
+ # Print XML
+ # puts alertsXML
+ print "POPCheckerImpl retrieved "+numberOfEmails.to_s+" new POP e-mail alerts\n"
+
+ # Return data as REXML document
+ result = Document.new(alertsXML)
+
+ return result
+end
+
+
+def getMessageField(field, message)
+
+ # Use a regex to get the field
+ pattern = '^'+field+': (.*?)$'
+
+ re = Regexp.new(pattern)
+ re =~ message
+
+ if $1 == nil
+ return ''
+ end
+
+ return $1
+end
+
+def encodeXML(data)
+ data = data.gsub(/</,'<')
+ data = data.gsub(/>/,'>')
+ return data
+end
+
+def stripXML(data)
+ data = data.gsub(/<.*?>/m,'')
+ data = data.gsub(/&.*?;/, ' ')
+ data = data.gsub(/&/, 'and')
+ data = encodeXML(data)
+ return data
+end
+
+
+
+# # Testing
+# pop = POPChecker.new()
+# print pop.getNewAlerts("mail.eclipse.co.uk", "andrew@borley-hall.eclipse.co.uk", "app73sauc3", "2007-01-29T02:15:53")
Propchange: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/POPCheckerImpl.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/POPCheckerImpl.rb
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/RSSCheckerImpl.py
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/RSSCheckerImpl.py?view=auto&rev=504759
==============================================================================
--- incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/RSSCheckerImpl.py (added)
+++ incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/RSSCheckerImpl.py Wed Feb 7 16:56:02 2007
@@ -0,0 +1,68 @@
+# 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.
+#
+
+import feedparser, datetime, xml.etree.ElementTree, re
+
+def getNewAlerts(rssaddress, lastchecktimestamp):
+
+ print "RSSCheckerImpl.getNewAlerts() called", rssaddress, lastchecktimestamp
+
+ #Get and parse the RSS/Atom data
+ d = feedparser.parse(rssaddress)
+
+ newalertsxml = "<alerts xmlns=\"http://tuscany.apache.org/samples/alerter\">\n"
+
+ lastcheckdate = datetime.datetime.min
+ if lastchecktimestamp:
+ lastcheckdate = datetime.datetime.strptime(lastchecktimestamp, "%Y-%m-%dT%H:%M:%S")
+
+ for entry in d.entries:
+
+ (year, month, day, hour, minute, second, millisecond, microsecond, tzinfo) = entry.date_parsed
+ entrydate = datetime.datetime(year, month, day, hour, minute, second)
+
+ if (entrydate > lastcheckdate) :
+
+ newalertsxml += "<alert><title>" + stripXML(entry.title) + "</title>\n"
+ newalertsxml += "<address>" + entry.link + "</address>\n"
+ newalertsxml += "<date>" + entrydate.isoformat() + "</date>\n"
+ newalertsxml += "<summary>" + stripXML(entry.description) + "</summary></alert>\n"
+ newalertsxml += "</alerts>"
+
+ return xml.etree.ElementTree.XML(newalertsxml)
+
+def stripXML(data):
+ elementsRemoved = re.sub("<.*?>","", data)
+ entitiesRemoved = re.sub("&.*?;", " ", elementsRemoved)
+ asciiEncoded = entitiesRemoved.encode('ASCII', 'replace')
+ returnData = asciiEncoded.replace('&', 'and')
+ return returnData
+
+
+# Testing
+# print xml.etree.ElementTree.tostring(getNewAlerts("http://www.engadget.com/rss.xml", "2007-02-07T17:11:14"))
+#
+#
+# today = datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
+# data2 = getNewAlerts("http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml", today.isoformat())
+# print xml.etree.ElementTree.tostring(data2)
+#
+# print "1st call returned", len(data.findall("./{http://tuscany.apache.org/samples/alerter}alert")), "elements"
+# print "2nd call returned", len(data2.findall("./{http://tuscany.apache.org/samples/alerter}alert")), "elements"
+
+
Propchange: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/RSSCheckerImpl.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/RSSCheckerImpl.py
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/sample.alerter.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/sample.alerter.composite?view=auto&rev=504759
==============================================================================
--- incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/sample.alerter.composite (added)
+++ incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/sample.alerter.composite Wed Feb 7 16:56:02 2007
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ name="sample.alerter">
+
+ <service name="AlerterService">
+ <binding.rest/>
+ <reference>AlertCheckerComponent</reference>
+ </service>
+
+ <component name="AlertCheckerComponent">
+ <implementation.python module="AlertCheckerImpl" scope="composite"/>
+ <reference name="alertConfigService">AlertConfigComponent</reference>
+ <reference name="rssCheckerService">RSSCheckerComponent</reference>
+ <reference name="popCheckerService">POPCheckerComponent</reference>
+ </component>
+
+ <component name="RSSCheckerComponent">
+ <implementation.python module="RSSCheckerImpl" scope="composite"/>
+ </component>
+
+ <component name="POPCheckerComponent">
+ <!--implementation.ruby script="POPCheckerImpl.rb" scope="stateless"/-->
+ <implementation.python module="POPCheckerImpl" scope="composite"/>
+ </component>
+
+ <component name="AlertConfigComponent">
+ <implementation.python module="AlertConfigImpl" scope="composite"/>
+ </component>
+
+</composite>
Propchange: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/sample.alerter.composite
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.alerter/sample.alerter.composite
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/Alerter.xsd
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/Alerter.xsd?view=auto&rev=504759
==============================================================================
--- incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/Alerter.xsd (added)
+++ incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/Alerter.xsd Wed Feb 7 16:56:02 2007
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schema targetNamespace="http://tuscany.apache.org/samples/alerter"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:ns="http://tuscany.apache.org/samples/alerter">
+ <element name="alerts" type="ns:alerts"/>
+
+ <complexType name="alert">
+ <sequence>
+ <element name="title" type="string"/>
+ <element name="summary" type="string"/>
+ <element name="address" type="anyURI" maxOccurs="1" minOccurs="1"/>
+ <element name="date" type="string" maxOccurs="1" minOccurs="1"/>
+ </sequence>
+ <attribute name="sourceid" type="string" use="optional"/>
+ </complexType>
+
+ <complexType name="alerts">
+ <sequence>
+ <element name="alert" type="ns:alert" maxOccurs="unbounded" minOccurs="0" />
+ </sequence>
+ </complexType>
+
+ <element name="config" type="ns:config"/>
+ <element name="source" type="ns:source"/>
+
+ <complexType name="source">
+ <sequence>
+ <element name="name" type="string" maxOccurs="1" minOccurs="1"/>
+ <element name="address" type="anyURI" maxOccurs="1" minOccurs="1"/>
+ <element name="lastChecked" type="string" maxOccurs="1" minOccurs="0"/>
+ <element name="feedAddress" type="string" maxOccurs="1" minOccurs="0"/>
+ <element name="popServer" type="string" maxOccurs="1" minOccurs="0"/>
+ <element name="popUsername" type="string" maxOccurs="1" minOccurs="0"/>
+ <element name="popPassword" type="string" maxOccurs="1" minOccurs="0"/>
+ <any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="id" type="string" use="optional"/>
+ <attribute name="type" use="required">
+ <simpleType>
+ <restriction base="string">
+ <enumeration value="rss"/>
+ <enumeration value="pop"/>
+ <enumeration value="nntp"/>
+ </restriction>
+ </simpleType>
+ </attribute>
+ </complexType>
+
+ <complexType name="config">
+ <sequence>
+ <element name="source" type="ns:source" maxOccurs="unbounded" minOccurs="0"/>
+ </sequence>
+ </complexType>
+</schema>
\ No newline at end of file
Propchange: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/Alerter.xsd
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/HTMLDisplayImpl.py
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/HTMLDisplayImpl.py?view=auto&rev=504759
==============================================================================
--- incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/HTMLDisplayImpl.py (added)
+++ incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/HTMLDisplayImpl.py Wed Feb 7 16:56:02 2007
@@ -0,0 +1,277 @@
+# 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.
+#
+#
+
+
+import xml.etree.ElementTree, datetime
+
+# Data structure to hold the alerts
+alertsElem = xml.etree.ElementTree.XML("<alerts xmlns=\"http://tuscany.apache.org/samples/alerter\"/>")
+
+# Data structure to map source_ids to source types
+sourceTypeMap = {}
+
+ns = "./{http://tuscany.apache.org/samples/alerter}"
+
+def getAlertsHTMLTable ():
+
+ returnData = "<TABLE border=\"0\">"
+
+ # Use the alertService reference
+ newAlertsElem = alertService.getAllNewAlerts();
+ #newAlertsElem = getAllNewAlerts(); # For testing
+
+ for alert in newAlertsElem.findall(ns+"alert"):
+
+ alert.attrib["unread"]="True"
+ alertsElem.append(alert)
+
+ # If we have more than x alerts, clear out any that have been read
+ # x is determined by the showNumberOfReadAlerts property
+ alerts = alertsElem.findall(ns+"alert")
+ if len(alerts) > int(showNumberOfReadAlerts):
+ for alert in alerts:
+ if alert.attrib["unread"]!="True":
+ alertsElem.remove(alert)
+
+ alertIDNumber = 0
+ for alert in alertsElem.findall(ns+"alert"):
+
+ date = datetime.datetime.strptime(alert.find(ns+"date").text, "%Y-%m-%dT%H:%M:%S")
+ alertID = "alert_"+str(alertIDNumber)
+ alert.attrib["id"]= alertID
+ alertIDNumber += 1
+
+ returnData += "<TR class=\"source_"
+ returnData += alert.attrib["sourceid"]
+ returnData += " clickable\" onclick=\"displayAlert('"
+ address = alert.find(ns+"address").text
+ if address != None:
+ returnData += address
+ returnData += "', '"+alertID+"')\"><TD><SPAN id=\""+alertID+"\" class=\""
+ if alert.attrib["unread"] == "True":
+ returnData += "unread_title"
+ else:
+ returnData += "read_title"
+ returnData += "\">"
+ title = alert.find(ns+"title").text
+ noOfChars = 75-len(title)
+
+ if noOfChars>0:
+ returnData += title
+ returnData += "</SPAN><SPAN class=\"summary\"> - "
+ returnData += alert.find(ns+"summary").text[0:noOfChars]
+ returnData += "...</SPAN></TD><TD>"
+ else:
+ returnData += title[0:80]
+ returnData += "</SPAN></TD><TD>"
+
+ returnData += date.strftime("%d/%m/%Y %I:%M %p")
+ returnData += "</TD></TR>\n"
+
+ returnData += "</TABLE>"
+
+ #print xml.etree.ElementTree.tostring(alertsElem)
+ return returnData
+
+def readAlert (alertID):
+
+ returnData = ""
+ for alert in alertsElem.findall(ns+"alert"):
+
+ if alert.attrib["id"]==alertID:
+ alert.attrib["unread"] = "False"
+
+ srcType = sourceTypeMap[alert.attrib["sourceid"]]
+ if srcType=="pop":
+ returnData += "<PRE>"
+ returnData += alert.find(ns+"summary").text
+ returnData += "</PRE>"
+ return returnData
+
+ return
+
+def getAlertSourcesHTMLTable():
+
+ returnData = "<TABLE border=\"0\">\n"
+
+ # Use the alertService reference
+ alertSources = alertService.getAlertSources()
+ #alertSources = getAlertSources() #testing
+
+ srcIdList = []
+
+ for source in alertSources.findall(ns+"source"):
+
+ srcId = source.attrib["id"]
+ srcIdList.append(srcId)
+ srcType = source.attrib["type"]
+
+ sourceTypeMap[srcId]=srcType
+
+ # Write out the source data row
+ returnData += "<TR CLASS=\"source_"
+ returnData += srcId
+ returnData += "\"><TD CLASS=\"clickable\" ONCLICK=\"displayAlert('"
+ returnData += source.find(ns+"address").text
+ returnData += "', '')\">"
+ returnData += "<IMG SRC=\""
+ returnData += srcType
+ returnData += ".png\"/> "
+ returnData += source.find(ns+"name").text
+ returnData += "</TD><TD CLASS=\"clickable link\" ONCLICK=\"showEditSource('"
+ returnData += srcId
+ returnData += "')\">Edit</TD><TD CLASS=\"clickable link\" ONCLICK=\"deleteSource('"
+ returnData += srcId
+ returnData += "')\">Delete</TD></TR>\n"
+
+ # Now write out the row that gets shown when "edit" is pressed
+ returnData += "<TR ID=\"edit_source_"
+ returnData += srcId
+ returnData += "\" CLASS=\"hidden source_"
+ returnData += srcId
+ returnData += "\"><TD COLSPAN=\"3\"><TABLE CLASS=\"sourceDetailsTable\"><TR><TD>Source name:</TD><TD><INPUT ID=\"source_"
+ returnData += srcId
+ returnData += "_name\" TYPE=\"TEXT\" SIZE=\"50\" VALUE=\""
+ returnData += source.find(ns+"name").text
+ returnData += "\"/></TR><TR><TD>Source address:</TD><TD><INPUT ID=\"source_"
+ returnData += srcId
+ returnData += "_address\" TYPE=\"TEXT\" SIZE=\"50\" VALUE=\""
+ returnData += source.find(ns+"address").text
+ returnData += "\"/></TR>"
+ if srcType=="rss":
+ returnData += "<TR><TD>Feed address:</TD><TD><INPUT ID=\"source_"
+ returnData += srcId
+ returnData += "_feedAddress\" TYPE=\"TEXT\" SIZE=\"50\" VALUE=\""
+ returnData += source.find(ns+"feedAddress").text
+ returnData += "\"/></TR>"
+ returnData += "<TR><TD><INPUT ID=\"source_"
+ returnData += srcId
+ returnData += "_type\" TYPE=\"HIDDEN\" VALUE=\""
+ returnData += srcType
+ returnData += "\"/><INPUT TYPE=\"BUTTON\" VALUE=\"Update\" ONCLICK=\"updateSource('"
+ returnData += srcId
+ returnData += "')\"><INPUT TYPE=\"BUTTON\" VALUE=\"Cancel\" ONCLICK=\"hideEditSource('"
+ returnData += srcId
+ returnData += "')\"></TR></TABLE></TD></TR>"
+
+ # Get the first unused srcId
+ srcId = "0"
+ while srcId in srcIdList:
+ srcId = str(int(srcId)+1)
+
+ # Now write out the "add new source" row
+ returnData += "<TR CLASS=\"source_"
+ returnData += srcId
+ returnData += "\"><TD COLSPAN=\"3\" CLASS=\"clickable link\" ONCLICK=\"showAddNewSource('"
+ returnData += srcId
+ returnData += "')\">Add new Alert Source</TD></TR>"
+ # Add the (initially hidden) new source details row
+ returnData += "<TR ID=\"add_source_"
+ returnData += srcId
+ returnData += "\"CLASS=\"hidden source_"
+ returnData += srcId
+ returnData += "\"><TD COLSPAN=\"3\"><TABLE CLASS=\"sourceDetailsTable\"><TR><TD>Source name:</TD><TD><INPUT ID=\"source_"
+ returnData += srcId
+ returnData += "_name\" TYPE=\"TEXT\" SIZE=\"50\"/></TD></TR><TR><TD>Source address:</TD><TD><INPUT ID=\"source_"
+ returnData += srcId
+ returnData += "_address\" TYPE=\"TEXT\" SIZE=\"50\"/></TD></TR><TR><TD>Source type:</TD><TD><SELECT ID=\"source_"
+ returnData += srcId
+ returnData += "_type\" ONCHANGE=\"showSourceType('"
+ returnData += srcId
+ returnData += "')\"><OPTION value=\"rss\" selected=\"selected\">RSS/Atom feed</OPTION>"
+ returnData += "<OPTION value=\"pop\">POP3 Email</OPTION></SELECT></TD></TR>"
+ # Section for RSS feeds
+ returnData += "<TR ID=\"add_rss_source\"><TD COLSPAN=\"2\"><TABLE CLASS=\"sourceDetailsTable\"><TR><TD>Feed address:</TD><TD><INPUT ID=\"source_"
+ returnData += srcId
+ returnData += "_feedAddress\" TYPE=\"TEXT\" SIZE=\"50\"/></TD></TR></TABLE></TD></TR>"
+ # Section for POP3 email
+ returnData += "<TR ID=\"add_pop_source\" CLASS=\"hidden\"><TD COLSPAN=\"2\"><TABLE CLASS=\"sourceDetailsTable\"><TR><TD>POP3 server:</TD><TD><INPUT ID=\"source_"
+ returnData += srcId
+ returnData += "_popServer\" TYPE=\"TEXT\" SIZE=\"50\"/></TR>"
+ returnData += "<TR><TD>Username:</TD><TD><INPUT ID=\"source_"
+ returnData += srcId
+ returnData += "_popUsername\" TYPE=\"TEXT\" SIZE=\"50\"/></TD></TR>"
+ returnData += "<TR><TD>Password:</TD><TD><INPUT ID=\"source_"
+ returnData += srcId
+ returnData += "_popPassword\" TYPE=\"PASSWORD\" SIZE=\"50\"/></TD></TR></TABLE></TD></TR>"
+ # Last row for buttons
+ returnData += "<TR><TD><INPUT TYPE=\"BUTTON\" VALUE=\"Add\" ONCLICK=\"addSource('"
+ returnData += srcId
+ returnData += "')\"><INPUT TYPE=\"BUTTON\" VALUE=\"Cancel\" ONCLICK=\"hideAddNewSource('"
+ returnData += srcId
+ returnData += "')\"></TD></TR></TABLE></TD></TR>"
+ returnData += "</TABLE>\n"
+ return returnData
+
+
+def deleteAlertSource (sourceId):
+ # Use the alertService reference
+ alertService.removeAlertSource(sourceId)
+
+ # Remove all alerts with this sourceid
+ for alert in alertsElem.findall(ns+"alert"):
+ if alert.attrib["sourceid"]==sourceId:
+ alertsElem.remove(alert)
+
+def addAlertSource(alertSourceElem):
+ if xml.etree.ElementTree.iselement(alertSourceElem):
+ # Use the alertService reference
+ alertService.addAlertSource(alertSourceElem)
+ return
+
+def updateAlertSource(alertSourceElem):
+
+ if xml.etree.ElementTree.iselement(alertSourceElem):
+ # Use the alertService reference
+ alertService.updateAlertSource(alertSourceElem)
+ return
+
+
+# # For testing
+# showNumberOfReadAlerts = 3
+#
+# def getAllNewAlerts ():
+#
+# data = "<alerts xmlns=\"http://tuscany.apache.org/samples/alerter\">"
+#
+# data += "<alert sourceid=\"0\" id=\"alert_0\"><title>Arrests over 'terror kidnap plot'</title>"
+# data += "<summary>Anti-terror police arrest eight people in Birmingham over an alleged plot to kidnap a member of the armed forces.</summary>"
+# data += "<address>http://news.bbc.co.uk/go/rss/-/1/hi/uk/6315989.stm</address><date>2007-01-31T15:34:18</date></alert>"
+#
+# data += "</alerts>"
+#
+# return xml.etree.ElementTree.XML(data)
+#
+# print getAlertsHTMLTable () + "\n"
+#
+# readAlert("http://news.bbc.co.uk/go/rss/-/1/hi/uk/6315989.stm")
+#
+# print getAlertsHTMLTable () + "\n"
+#
+# def getAlertSources ():
+#
+# data = "<config xmlns=\"http://tuscany.apache.org/samples/alerter\">"
+# data += "<source id=\"0\" type=\"rss\"><name>BBC News</name>"
+# data += "<address>http://news.bbc.co.uk/</address>"
+# data += "<lastChecked>2007-02-02T10:08:40</lastChecked>"
+# data += "<feedAddress>http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml</feedAddress></source>"
+# data += "</config>"
+# return xml.etree.ElementTree.XML(data)
+#
+# print getAlertSourcesHTMLTable()
Propchange: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/HTMLDisplayImpl.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/HTMLDisplayImpl.py
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/Makefile.am?view=auto&rev=504759
==============================================================================
--- incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/Makefile.am (added)
+++ incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/Makefile.am Wed Feb 7 16:56:02 2007
@@ -0,0 +1,23 @@
+# 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.
+
+deploydir=$(prefix)/samples/AlertAggregator/deploy
+compositedir=$(deploydir)/sample.display
+
+composite_DATA = *.composite *.py *.xsd
+EXTRA_DIST = *.composite *.py *.xsd
+
Propchange: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/Makefile.am
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/Makefile.am
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/sample.display.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/sample.display.composite?view=auto&rev=504759
==============================================================================
--- incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/sample.display.composite (added)
+++ incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/sample.display.composite Wed Feb 7 16:56:02 2007
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ name="sample.display">
+
+ <service name="HTMLDisplayService">
+ <binding.rest/>
+ <reference>HTMLDisplayComponent</reference>
+ </service>
+
+ <component name="HTMLDisplayComponent">
+ <implementation.python module="HTMLDisplayImpl" scope="composite"/>
+ <reference name="alertService">AlerterService</reference>
+ <property name="showNumberOfReadAlerts">20</property>
+ </component>
+
+ <reference name="AlerterService">
+ <binding.rest/>
+ </reference>
+
+</composite>
\ No newline at end of file
Propchange: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/sample.display.composite
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/sample.display.composite
------------------------------------------------------------------------------
svn:keywords = Rev Date
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org