Revision: 1898
Author: [email protected]
Date: Mon Jun 7 06:49:29 2010
Log: Widget must be serializable and not all Widget attributes are always
present.
http://code.google.com/p/simal/source/detail?r=1898
Modified:
/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/Widget.java
Tue Feb 16 01:53:18 2010
+++
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/widgets/Widget.java
Mon Jun 7 06:49:29 2010
@@ -16,16 +16,21 @@
* specific language governing permissions and limitations *
* under the License. *
*/
+import java.io.Serializable;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
-public class Widget {
- String identifier;
+public class Widget implements Serializable{
+
+ private static final long serialVersionUID = 2625929235339451020L;
+
+ String identifier;
String title;
String description;
URL icon;
@@ -80,18 +85,30 @@
*/
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();
+ String url = getElementTextContent(rootEl, "url");
+ String id = getElementTextContent(rootEl, "identifier");
+ String title = getElementTextContent(rootEl, "title");
+ String height = getElementTextContent(rootEl, "height");
+ String width = getElementTextContent(rootEl, "width");
+ String maximize = getElementTextContent(rootEl, "maximize");
Instance instance = new Instance(url, id, title, height, width,
maximize);
instances.put(id, instance);
return instance;
}
+
+ private String getElementTextContent(Element rootEl, String tagName) {
+ String textContent = "";
+
+ NodeList nodeList = rootEl.getElementsByTagName(tagName);
+ if(nodeList != null && nodeList.getLength() > 0) {
+ textContent = nodeList.item(0).getTextContent();
+ }
+
+ return textContent;
+ }
+
/**
* An instance of this widget.
*
--
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.