Revision: 1782
Author: [email protected]
Date: Sun Dec 13 15:18:48 2009
Log: Add support for a Wookie Server and add some test features to the  
ToolsPage.

Currently we list all available widgets on the ToolsPage. Alongside each  
widget we have an "instantiate" link. This takes us to a page showing us  
the widget in action.

Returning to the ToolsPage will now show this (and any other previously  
instantiated widgets).

This work allows us to expose features of Simal as Widgets, thus making it  
easy to embed Simal into other applications.

Note that, at present, there is no support for different users or per  
application API keys so this is not ready for the big time yet (per  
instance widgets, multi-user widgets, etc.)
http://code.google.com/p/simal/source/detail?r=1782

Added:
   
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets
   
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/InstantiateWidgetPage.html
   
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/InstantiateWidgetPage.java
   
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/Widget.java
   
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/WookieServerConnection.java
   
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/WookieWidgetGalleryPanel.html
   
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/WookieWidgetGalleryPanel.java
   
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/WookieWidgetPanel.html
   
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/WookieWidgetPanel.java
Modified:
  /trunk/uk.ac.osswatch.simal.web/.classpath
  /trunk/uk.ac.osswatch.simal.web/.project
   
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/ToolsPage.html
   
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/ToolsPage.java
   
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/UserApplication.java

=======================================
--- /dev/null
+++  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/InstantiateWidgetPage.html
     
Sun Dec 13 15:18:48 2009
@@ -0,0 +1,63 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
+<!--
+  Copyright 2009 University of Oxford
+
+  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.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml";>
+<head>
+  <title>Instantiate Widget</title>
+</head>
+<body>
+<wicket:extend>
+<h1>Widget Instantiated</h1>
+
+<h2>Widget Instance</h2>
+<div wicket:id="widget">
+  <p>A wookie widget</p>
+</div>
+
+<h2>Widget Details</h2>
+
+<table>
+  <tr>
+    <th>ID</th>
+    <td wicket:id="id">ID</td>
+  </tr>
+  <tr>
+    <th>Title</th>
+    <td wicket:id="title">title</td>
+  </tr>
+  <tr>
+    <th>URL</th>
+    <td wicket:id="url">URL</td>
+  </tr>
+  <tr>
+    <th>Height</th>
+    <td wicket:id="height">height</td>
+  </tr>
+  <tr>
+    <th>Width</th>
+    <td wicket:id="width">Width</td>
+  </tr>
+  <tr>
+    <th>Maximize</th>
+    <td wicket:id="maximize">maximize</td>
+  </tr>
+</table>
+
+</wicket:extend>
+</body>
+</html>
+
=======================================
--- /dev/null
+++  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/InstantiateWidgetPage.java
     
Sun Dec 13 15:18:48 2009
@@ -0,0 +1,89 @@
+package uk.ac.osswatch.simal.wicket.widgets;
+
+/*
+ * Copyright 2009 University of Oxford
+ *
+ * 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.                                                *
+ */
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.wicket.Page;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.IPageLink;
+import org.apache.wicket.markup.html.link.Link;
+
+import uk.ac.osswatch.simal.wicket.BasePage;
+import uk.ac.osswatch.simal.wicket.ErrorReportPage;
+import uk.ac.osswatch.simal.wicket.UserApplication;
+import uk.ac.osswatch.simal.wicket.UserReportableException;
+import uk.ac.osswatch.simal.wicket.widgets.Widget.Instance;
+
+/**
+ * Called when a widget needs to be instantiated. This page will attempt to
+ * instantiate the widget and will return information about the widget to  
the user.
+ */
+public class InstantiateWidgetPage extends BasePage {
+
+       /**
+        * Attempt to instantiate a widget using a wookie server.
+        *
+        * @param parameters
+        * @throws UnsupportedEncodingException
+        */
+       public InstantiateWidgetPage(Widget widget) {
+      Instance instance;
+         try {
+                 instance =  
UserApplication.getWookieServerConnection().getOrCreateInstance(widget);
+                 populatePage(instance);
+         } catch (IOException e) {
+         UserReportableException error = new UserReportableException(
+                         "Problem communicating with Wookie server",  
InstantiateWidgetPage.class);
+                 setResponsePage(new ErrorReportPage(error));
+         }
+       }
+
+       /**
+        * Populate the page with the details of the instantiated widget.
+        *
+        * @param id
+        */
+       private void populatePage(Widget.Instance instance) {
+           add(new WookieWidgetPanel("widget", instance));
+
+               add(new Label("id", instance.getId()));
+               add(new Label("title", instance.getTitle()));
+               add(new Label("url", instance.getUrl()));
+               add(new Label("height", instance.getHeight()));
+               add(new Label("width", instance.getWidth()));
+               add(new Label("maximize", instance.getMaximize()));
+       }
+
+       /**
+          * Get a link to an InstantiateWidgetPage for a widget.
+          *
+          * @param widget
+          *          the widget we want to instantiate with this page
+          * @return
+          */
+         public static Link getLink(final String id, final Widget widget) {
+          return new Link(id) {
+                  public void onClick(){
+                          setResponsePage(new InstantiateWidgetPage(widget));
+             }
+          };
+         }
+}
+
=======================================
--- /dev/null
+++  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/Widget.java
    
Sun Dec 13 15:18:48 2009
@@ -0,0 +1,174 @@
+package uk.ac.osswatch.simal.wicket.widgets;
+
+/*
+ * Copyright 2008 University of Oxford
+ *
+ * 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.                                                *
+ */
+import java.net.URL;
+import java.util.Collection;
+import java.util.HashMap;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+
+public class Widget {
+       String identifier;
+       String title;
+       String description;
+       URL icon;
+       HashMap<String, Instance> instances = new HashMap<String, Instance>();
+
+       public Widget(String identifier, String title, String description, URL  
icon) {
+               this.identifier = identifier;
+               this.title = title;
+               this.description = description;
+               this.icon = icon;
+       }
+
+       /**
+        * Get a unique identifier for this widget type.
+        *
+        * @return
+        */
+       public String getIdentifier() {
+               return identifier;
+       }
+
+       /**
+        * Get the human readable title of this widget.
+        * @return
+        */
+       public String getTitle() {
+               return title;
+       }
+
+       /**
+        * Get the location of a logo for this widget.
+        * @return
+        */
+       public URL getIcon() {
+               return icon;
+       }
+
+       /**
+        * Get the description of the widget.
+        *
+        * @return
+        */
+       public String getDescription() {
+               return description;
+       }
+
+       /**
+        * Record an instance of the given widget.
+        *
+        * @param xml description of the instance as returned by the widget  
server when the widget was instantiated.
+        * @return the identifier for this instance
+        */
+       public Instance addInstance(Document xml) {
+               Element rootEl = xml.getDocumentElement();
+               String url = 
rootEl.getElementsByTagName("url").item(0).getTextContent();
+               String id =  
rootEl.getElementsByTagName("identifier").item(0).getTextContent();
+               String title =  
rootEl.getElementsByTagName("title").item(0).getTextContent();
+               String height =  
rootEl.getElementsByTagName("height").item(0).getTextContent();
+               String width =  
rootEl.getElementsByTagName("width").item(0).getTextContent();
+               String maximize =  
rootEl.getElementsByTagName("maximize").item(0).getTextContent();
+               Instance instance = new Instance(url, id, title, height, width, 
 
maximize);
+               instances.put(id, instance);
+
+               return instance;
+       }
+
+       /**
+        * An instance of this widget.
+        *
+        */
+       public class Instance {
+               String url;
+
+               String id;
+               String title;
+               String height;
+               String width;
+               String maximize;
+
+               public Instance(String url, String id, String title, String 
height,
+                               String width, String maximize) {
+                       setId(id);
+                       setUrl(url);
+                       setTitle(title);
+                       setHeight(height);
+                       setWidth(width);
+                       setMaximize(maximize);
+               }
+
+               public String getUrl() {
+                       return url;
+               }
+
+               public void setUrl(String url) {
+                       this.url = url;
+               }
+
+               public String getId() {
+                       return id;
+               }
+
+               public void setId(String id) {
+                       this.id = id;
+               }
+
+               public String getTitle() {
+                       return title;
+               }
+
+               public void setTitle(String title) {
+                       this.title = title;
+               }
+
+               public String getHeight() {
+                       return height;
+               }
+
+               public void setHeight(String height) {
+                       this.height = height;
+               }
+
+               public String getWidth() {
+                       return width;
+               }
+
+               public void setWidth(String width) {
+                       this.width = width;
+               }
+
+               public String getMaximize() {
+                       return maximize;
+               }
+
+               public void setMaximize(String maximize) {
+                       this.maximize = maximize;
+               }
+       }
+
+       /**
+        * Get all instances of a widget available in this server.
+        * @return
+        */
+       public Collection<Instance> getInstances() {
+               return instances.values();
+       }
+}
=======================================
--- /dev/null
+++  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/WookieServerConnection.java
    
Sun Dec 13 15:18:48 2009
@@ -0,0 +1,197 @@
+package uk.ac.osswatch.simal.wicket.widgets;
+/*
+ * Copyright 2009 University of Oxford
+ *
+ * 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.                                                *
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.util.HashMap;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import uk.ac.osswatch.simal.rdf.SimalException;
+import uk.ac.osswatch.simal.wicket.widgets.Widget.Instance;
+
+/**
+ * A connection to a Woolkie server. This maintains the necessary data for  
connecting
+ * to the server and provides utility methods for making common calls via  
the Wookie
+ * REST API.
+ *
+ */
+public class WookieServerConnection implements Serializable {
+       private static final long serialVersionUID = 1L;
+       private String wookieURL = "http://localhost:8888/wookie";;
+       private HashMap<String, Widget> widgets = new HashMap<String, Widget>();
+
+       /**
+        * Get the URL of the wookie server.
+        *
+        * @return
+        */
+       public String getURL() {
+               return wookieURL;
+       }
+
+       /**
+        * Get the API key for this server.
+        *
+        * @return
+        */
+       public String getApiKey() {
+               return "TEST";
+       }
+
+       /**
+        * Get the user identifier for this user and server.
+        * @return
+        */
+       public String getUserID() {
+               return "testuser";
+       }
+
+       /**
+        * Get the shared data key for this server.
+        *
+        * @return
+        */
+       public String getSharedDatakey() {
+               return "mysharedkey";
+       }
+
+       /**
+        * Get or create an instance of a widget.
+        * @param widget
+        * @return the ID of the widget instance
+        * @throws IOException
+        */
+       public Widget.Instance getOrCreateInstance(Widget widget) throws  
IOException {
+               StringBuffer data = new StringBuffer();
+                 try {
+                         data.append(URLEncoder.encode("api_key", "UTF-8"));
+                         data.append("=");
+                         data.append(URLEncoder.encode(getApiKey(), "UTF-8"));
+                         data.append("&");
+                         data.append(URLEncoder.encode("userid", "UTF-8"));
+                         data.append("=");
+                         data.append(URLEncoder.encode(getUserID(), "UTF-8"));
+                         data.append("&");
+                         data.append(URLEncoder.encode("shareddatakey", 
"UTF-8"));
+                         data.append("=");
+                         data.append(URLEncoder.encode(getSharedDatakey(), 
"UTF-8"));
+                         data.append("&");
+                         data.append(URLEncoder.encode("widgetid", "UTF-8"));
+                         data.append("=");
+                         data.append(URLEncoder.encode(widget.getIdentifier(), 
"UTF-8"));
+                 } catch (UnsupportedEncodingException e) {
+                       throw new RuntimeException("UTF-8 encoding must be 
supported on the  
server", e);
+                 }
+
+             URL url;
+                 Instance instance;
+               try {
+                       url = new URL(getURL() + "/widgetinstances");
+                       URLConnection conn = url.openConnection();
+               conn.setDoOutput(true);
+               OutputStreamWriter wr = new  
OutputStreamWriter(conn.getOutputStream());
+               wr.write(data.toString());
+               wr.flush();
+
+               InputStream is = conn.getInputStream();
+
+               DocumentBuilderFactory dbf = 
DocumentBuilderFactory.newInstance();
+                       DocumentBuilder db = dbf.newDocumentBuilder();
+                       instance = widget.addInstance(db.parse(is));
+
+               wr.close();
+               is.close();
+                 } catch (MalformedURLException e) {
+                         throw new RuntimeException("URL for supplied Wookie 
Server is  
malformed", e);
+             } catch (ParserConfigurationException e) {
+                         throw new RuntimeException("Unable to configure XML 
parser", e);
+               } catch (SAXException e) {
+                         throw new RuntimeException("Problem parsing XML from 
Wookie Server",  
e);
+               }
+
+               return instance;
+       }
+
+       /**
+        * Get a set of all the available widgets in the server.
+        *
+        * @return
+        * @throws SimalException
+        */
+       public HashMap<String, Widget> getAvailableWidgets() throws  
SimalException {
+           try {
+               InputStream is = new URL(getURL()  
+ "/widgets?all=true").openStream();
+               DocumentBuilderFactory dbf = 
DocumentBuilderFactory.newInstance();
+                       DocumentBuilder db = dbf.newDocumentBuilder();
+                       Document widgetsDoc = db.parse(is);
+
+                       Element root = widgetsDoc.getDocumentElement();
+                       NodeList widgetList = 
root.getElementsByTagName("widget");
+                       for (int idx = 0; idx < widgetList.getLength(); idx = 
idx + 1) {
+                               String name, identifier, desc;
+                               URL icon;
+                               Element widgetEl = 
(Element)widgetList.item(idx);
+                               name = 
widgetEl.getElementsByTagName("title").item(0).getTextContent();
+                               if (widgets.containsKey(name)) {
+                                       break;
+                               }
+                               desc =  
widgetEl.getElementsByTagName("description").item(0).getTextContent();
+                               try {
+                                       Node iconElement = 
widgetEl.getElementsByTagName("icon").item(0);
+                                       if (iconElement != null) {
+                                       icon = new 
URL(iconElement.getTextContent());
+                                       } else {
+                                               throw new 
MalformedURLException(null);
+                                       }
+                               } catch (MalformedURLException e) {
+                                       // FIXME: Create a default URL for 
widget logos
+                                       icon = new 
URL("http://www.oss-watch.ac.uk/images/logo2.gif";);
+                               }
+                               identifier = 
widgetEl.getAttribute("identifier");
+
+                               widgets.put(name, new Widget(identifier, name, 
desc, icon));
+                       }
+               } catch (ParserConfigurationException e) {
+             throw new SimalException("Unable to create XML parser", e);
+               } catch (MalformedURLException e) {
+                     throw new SimalException("URL for Wookie is malformed", 
e);
+               } catch (IOException e) {
+                     throw new SimalException("Problem communicating with the 
Wookie  
server", e);
+               } catch (SAXException e) {
+                     throw new SimalException("Unable to parse the response 
from  
Wookie", e);
+               }
+               return widgets;
+       }
+
+}
=======================================
--- /dev/null
+++  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/WookieWidgetGalleryPanel.html
  
Sun Dec 13 15:18:48 2009
@@ -0,0 +1,35 @@
+<!--
+
+Copyright 2008 University of Oxford
+ 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.
+
+-->
+
+<html xmlns:wicket>
+<wicket:panel>
+  <div wicket:id="gallery">
+    <table>
+      <tr>
+        <td rowspan="2" width="20%"><img wicket:id="icon"  
src="http://www.oss-watch.ac.uk/images/logo.png"/></td>
+        <td><span wicket:id="name">Name</span>
+            (<a wicket:id="instantiate"  
href="#instantiate">instantiate</a>)</td>
+      </tr>
+      <tr>
+        <td><span wicket:id="description">Description</span></td>
+      </tr>
+    </table>
+  </div>
+</wicket:panel>
+</html>
+
=======================================
--- /dev/null
+++  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/WookieWidgetGalleryPanel.java
  
Sun Dec 13 15:18:48 2009
@@ -0,0 +1,93 @@
+package uk.ac.osswatch.simal.wicket.widgets;
+
+/*
+ * Copyright 2008 University of Oxford
+ *
+ * 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.                                                *
+ */
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.wicket.markup.ComponentTag;
+import org.apache.wicket.markup.html.WebComponent;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.markup.repeater.RepeatingView;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import uk.ac.osswatch.simal.rdf.SimalException;
+import uk.ac.osswatch.simal.wicket.UserApplication;
+
+/**
+ * A panel to display a Wookie Widget. See  
http://incubator.apache.org/wookie
+ */
+public class WookieWidgetGalleryPanel extends Panel {
+  private static final long serialVersionUID = 1L;
+  private static final Logger logger =  
LoggerFactory.getLogger(WookieWidgetGalleryPanel.class);
+
+  /**
+   * Create a default Wookie Widget gallery panel that will display all the
+   * available widgets on a server.
+   *
+   * @param id the wiketID of this component
+   * @throws SimalException if unable to build gallery
+   */
+  public WookieWidgetGalleryPanel(String id) throws SimalException {
+    super(id);
+     
populatePanel(UserApplication.getWookieServerConnection().getAvailableWidgets());
+  }
+
+  /**
+   * Populate the panel with data.
+   * @param hashMap
+   *
+   */
+  private void populatePanel(HashMap<String, Widget> hashMap) {
+    RepeatingView repeating = new RepeatingView("gallery");
+    Iterator<Widget> itr = hashMap.values().iterator();
+    Widget widget;
+       while(itr.hasNext()) {
+         WebMarkupContainer item = new  
WebMarkupContainer(repeating.newChildId());
+         repeating.add(item);
+         widget = itr.next();
+
+         item.add(new StaticImage("icon", new  
Model(widget.getIcon().toExternalForm())));
+         item.add(new Label("name", widget.getTitle()));
+         item.add(new Label("description", widget.getDescription()));
+
+         item.add(InstantiateWidgetPage.getLink("instantiate", widget));
+       }
+       add(repeating);
+  }
+
+  public class StaticImage extends WebComponent {
+
+      public StaticImage(String id, IModel model) {
+          super(id, model);
+      }
+
+      protected void onComponentTag(ComponentTag tag) {
+          super.onComponentTag(tag);
+          checkComponentTag(tag, "img");
+          tag.put("src", getDefaultModelObjectAsString());
+      }
+
+  }
+}
=======================================
--- /dev/null
+++  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/WookieWidgetPanel.html
         
Sun Dec 13 15:18:48 2009
@@ -0,0 +1,25 @@
+<!--
+
+Copyright 2008 University of Oxford
+ 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.
+
+-->
+
+<html xmlns:wicket>
+<wicket:panel>
+  <div>
+    <iframe wicket:id="widget" src="#widgetURL"></iframe>
+  </div>
+</wicket:panel>
+</html>
=======================================
--- /dev/null
+++  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/WookieWidgetPanel.java
         
Sun Dec 13 15:18:48 2009
@@ -0,0 +1,57 @@
+package uk.ac.osswatch.simal.wicket.widgets;
+
+/*
+ * Copyright 2008 University of Oxford
+ *
+ * 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.                                                *
+ */
+
+import org.apache.wicket.behavior.SimpleAttributeModifier;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A panel to display a Wookie Widget. See  
http://incubator.apache.org/wookie
+ */
+public class WookieWidgetPanel extends Panel {
+  private static final long serialVersionUID = 1L;
+  private static final Logger logger =  
LoggerFactory.getLogger(WookieWidgetPanel.class);
+
+  /**
+   * Create a default Wookie Widget.
+   *
+   * @param id the wiketID of this component
+   * @param instance the widget instance to display
+   */
+  public WookieWidgetPanel(String id, Widget.Instance instance) {
+    super(id);
+    populatePanel(instance);
+  }
+
+  /**
+   * Populate the panel with data.
+   *
+   */
+  private void populatePanel(Widget.Instance instance) {
+    WebMarkupContainer iFrame = new WebMarkupContainer("widget");
+    iFrame.setOutputMarkupId(true);
+    iFrame.add(new SimpleAttributeModifier("src", instance.getUrl()));
+    iFrame.add(new SimpleAttributeModifier("height",  
instance.getHeight()));
+    iFrame.add(new SimpleAttributeModifier("width", instance.getWidth()));
+    add(iFrame);
+  }
+
+}
=======================================
--- /trunk/uk.ac.osswatch.simal.web/.classpath  Wed Nov 25 13:35:02 2009
+++ /trunk/uk.ac.osswatch.simal.web/.classpath  Sun Dec 13 15:18:48 2009
@@ -1,11 +1,14 @@
  <?xml version="1.0" encoding="UTF-8"?>
  <classpath>
-       <classpathentry including="**/*.java" kind="src"  
output="target-eclipse/test-classes" path="src/test/java"/>
+       <classpathentry including="**/*.java" kind="src"  
output="target/test-classes" path="src/test/java"/>
        <classpathentry including="**/*.java" kind="src" path="src/main/java"/>
-       <classpathentry kind="src" path="src/main/resources"/>
-       <classpathentry kind="con"  
path="org.eclipse.iam.jdt.core.mavenClasspathContainer"/>
+       <classpathentry kind="con"  
path="org.eclipse.iam.jdt.core.mavenClasspathContainer">
+               <attributes>
+                       <attribute name="org.eclipse.jst.component.dependency"  
value="/WEB-INF/lib"/>
+               </attributes>
+       </classpathentry>
+       <classpathentry kind="con"  
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
        <classpathentry combineaccessrules="false" kind="src"  
path="/uk.ac.osswatch.simal.core"/>
        <classpathentry combineaccessrules="false" kind="src"  
path="/uk.ac.osswatch.simal.rest"/>
-       <classpathentry kind="con"  
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-       <classpathentry kind="output" path="target-eclipse/classes"/>
+       <classpathentry kind="output" path="target/classes"/>
  </classpath>
=======================================
--- /trunk/uk.ac.osswatch.simal.web/.project    Sat Jun 20 15:27:06 2009
+++ /trunk/uk.ac.osswatch.simal.web/.project    Sun Dec 13 15:18:48 2009
@@ -22,8 +22,8 @@
                </buildCommand>
        </buildSpec>
        <natures>
+               <nature>org.devzuz.q.maven.jdt.core.mavenNature</nature>
                <nature>org.eclipse.iam.jdt.core.mavenNature</nature>
                <nature>org.eclipse.jdt.core.javanature</nature>
-               <nature>org.devzuz.q.maven.jdt.core.mavenNature</nature>
        </natures>
  </projectDescription>
=======================================
---  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/ToolsPage.html
         
Mon Nov  9 22:35:54 2009
+++  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/ToolsPage.html
         
Sun Dec 13 15:18:48 2009
@@ -133,6 +133,23 @@
      </fieldset>
    </form>

+  <hr/>
+  <h1>Wicket Widgets</h1>
+  <div class="content">
+         <div class="leftcolumn">
+                 <h2>Available Widgets</h2>
+                 <div wicket:id="widgetGallery">
+                   <p>Widget Gallery</p>
+                 </div>
+         </div>
+         <div class="rightcolumn">
+                 <h2>Instantiated Widgets</h2>
+                 <div wicket:id="instantiatedWidgets">
+                   <div wicket:id="instance">Widget instance</div>
+                 </div>
+         </div>
+  </div>
+
  </wicket:extend>
  </body>
  </html>
=======================================
---  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/ToolsPage.java
         
Mon Nov  9 22:35:54 2009
+++  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/ToolsPage.java
         
Sun Dec 13 15:18:48 2009
@@ -21,8 +21,11 @@
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.net.MalformedURLException;
+import java.util.Collection;
+import java.util.Iterator;

  import  
org.apache.wicket.extensions.ajax.markup.html.form.upload.UploadProgressBar;
+import org.apache.wicket.markup.html.WebMarkupContainer;
  import org.apache.wicket.markup.html.basic.Label;
  import org.apache.wicket.markup.html.form.Form;
  import org.apache.wicket.markup.html.form.TextField;
@@ -30,6 +33,7 @@
  import org.apache.wicket.markup.html.form.upload.FileUploadField;
  import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.repeater.RepeatingView;
  import org.apache.wicket.model.CompoundPropertyModel;
  import org.apache.wicket.util.file.Files;
  import org.apache.wicket.util.file.Folder;
@@ -50,6 +54,11 @@
  import uk.ac.osswatch.simal.wicket.doap.ExhibitProjectBrowserPage;
  import uk.ac.osswatch.simal.wicket.foaf.ExhibitPersonBrowserPage;
  import uk.ac.osswatch.simal.wicket.tools.OhlohFormInputModel;
+import uk.ac.osswatch.simal.wicket.widgets.Widget;
+import uk.ac.osswatch.simal.wicket.widgets.WookieServerConnection;
+import uk.ac.osswatch.simal.wicket.widgets.WookieWidgetGalleryPanel;
+import uk.ac.osswatch.simal.wicket.widgets.WookieWidgetPanel;
+import uk.ac.osswatch.simal.wicket.widgets.Widget.Instance;

  /**
   * The tools page provides access to a number of useful Admin tools.
@@ -163,6 +172,35 @@
          ExhibitPersonBrowserPage.class));
      add(new BookmarkablePageLink("exhibitProjectLink",
              ExhibitProjectBrowserPage.class));
+
+    // Widget testing
+    // all widgets in a gallery
+       try {
+               add(new WookieWidgetGalleryPanel("widgetGallery"));
+       } catch (SimalException e) {
+               UserReportableException ure = new 
UserReportableException("Unable to  
retrieve widgets from Woookie for Gallery", ToolsPage.class, e);
+        setResponsePage(new ErrorReportPage(ure));
+    }
+       // all instantiated widgets
+       try {
+           RepeatingView repeating = new RepeatingView("instantiatedWidgets");
+           Iterator<Widget> itr =  
UserApplication.getWookieServerConnection().getAvailableWidgets().values().iterator();
+           Widget widget;
+               while(itr.hasNext()) {
+                 widget = itr.next();
+             Iterator<Widget.Instance> instances =  
widget.getInstances().iterator();
+             while(instances.hasNext()) {
+                 Instance instance = instances.next();
+                         WebMarkupContainer item = new  
WebMarkupContainer(repeating.newChildId());
+                         repeating.add(item);
+                         item.add(new WookieWidgetPanel("instance", instance));
+             }
+               }
+               add(repeating);
+       } catch (SimalException e) {
+               UserReportableException ure = new 
UserReportableException("Unable to  
retrieve widgets from Woookie for Gallery", ToolsPage.class, e);
+        setResponsePage(new ErrorReportPage(ure));
+    }
    }

    /**
=======================================
---  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/UserApplication.java
   
Mon Nov 23 14:59:58 2009
+++  
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/UserApplication.java
   
Sun Dec 13 15:18:48 2009
@@ -44,6 +44,7 @@
  import uk.ac.osswatch.simal.wicket.doap.ProjectDetailPage;
  import uk.ac.osswatch.simal.wicket.foaf.ExhibitPersonBrowserPage;
  import uk.ac.osswatch.simal.wicket.foaf.PersonDetailPage;
+import uk.ac.osswatch.simal.wicket.widgets.WookieServerConnection;

  /**
   * The UserApp is the main user facing appliation. This application allows  
users
@@ -59,6 +60,8 @@

        private static Timer ptswTimer;

+       private static WookieServerConnection wookieServerConnection;
+
        public UserApplication() {
                setScheduledPtswStatus(true);
        }
@@ -182,4 +185,15 @@
                        ptswTimer = null;
                }
        }
-}
+
+       /**
+        * Get a connection to the Wookie Server used for gadget rendering.
+        * @return
+        */
+       public static WookieServerConnection getWookieServerConnection() {
+               if (wookieServerConnection == null) {
+                       wookieServerConnection = new WookieServerConnection();
+               }
+               return wookieServerConnection;
+       }
+}

--

You received this message because you are subscribed to the Google Groups 
"Simal Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/simal-commits?hl=en.


Reply via email to