Added additional tag to XML parser.

This commit is contained in:
Robert Kolner committed 2011-09-21 20:04:10 +02:00
1 parent 62f3406d1f
commit 1d1a1cbed8
5 files changed
+32 -11

No files matched your search

@@ -5,12 +5,12 @@ import java.util.LinkedList;
public class DataHandler {
private LinkedList<Event> events = new LinkedList<Event>();
public void insert(String id, String title, String description, String date, String location, String category) {
public void insert(String id, String title, String description, String date, String location, String text, String category) {
int intId = Integer.parseInt(id);
if (get(intId) != null)
return;
Event e = new Event(intId, title, description, date, location, category);
Event e = new Event(intId, title, description, date, location, text, category);
events.add(e);
}
+4 -1
View File
@@ -9,6 +9,7 @@ public class Event implements Serializable {
public String description;
public String date;
public String location;
public String text;
public String category;
public Event(
@@ -16,13 +17,15 @@ public class Event implements Serializable {
String title,
String description,
String date,
String location,
String location,
String text,
String category) {
this.id = id;
this.title = title;
this.description = description;
this.date = date;
this.location = location;
this.text = text;
this.category = category;
}
+13 -7
View File
@@ -17,6 +17,7 @@ public class XmlParser {
String description = "";
String date = "";
String location = "";
String text = "";
String category = "";
// String pictureUrl = ""; Necessary?
@@ -33,6 +34,7 @@ public class XmlParser {
NodeList descriptionNodes = (itemElement).getElementsByTagName("description");
NodeList dateNodes = (itemElement).getElementsByTagName("date");
NodeList locationNodes = (itemElement).getElementsByTagName("location");
NodeList textNodes = (itemElement).getElementsByTagName("text");
NodeList categoryNodes = (itemElement).getElementsByTagName("category");
// Convert a Node into an Element.
@@ -41,6 +43,7 @@ public class XmlParser {
Node descriptionElement = descriptionNodes.item(0);
Node dateElement = dateNodes.item(0);
Node locationElement = locationNodes.item(0);
Node textElement = textNodes.item(0);
Node categoryElement = categoryNodes.item(0);
// Get all the child nodes.
@@ -49,16 +52,19 @@ public class XmlParser {
NodeList descriptionTextNodes = descriptionElement.getChildNodes();
NodeList dateTextNodes = dateElement.getChildNodes();
NodeList locationTextNodes = locationElement.getChildNodes();
NodeList textTextNodes = textElement.getChildNodes();
NodeList categoryTextNodes = categoryElement.getChildNodes();
// Retrieve the text.
id = idTextNodes.item(0).getNodeValue();
title = titleTextNodes.item(0).getNodeValue();
description = descriptionTextNodes.item(0).getNodeValue();
date = dateTextNodes.item(0).getNodeValue();
location = locationTextNodes.item(0).getNodeValue();
category = categoryTextNodes.item(0).getNodeValue();
dh.insert(id, title, description, date, location, category);
id = idTextNodes.item(0).getNodeValue(); // mandatory
title = titleTextNodes.item(0).getNodeValue(); // mandatory
if (descriptionTextNodes.getLength() > 0) description = descriptionTextNodes.item(0).getNodeValue();
if (dateTextNodes.getLength() > 0) date = dateTextNodes.item(0).getNodeValue();
if (locationTextNodes.getLength() > 0) location = locationTextNodes.item(0).getNodeValue();
if (textTextNodes.getLength() > 0) text = textTextNodes.item(0).getNodeValue();
if (categoryTextNodes.getLength() > 0) category = categoryTextNodes.item(0).getNodeValue();
dh.insert(id, title, description, date, location, text, category);
}
}
return dh;
@@ -3,6 +3,7 @@ package com.studentersamfundet.app.ui;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
@@ -31,10 +32,20 @@ public class EventViewActivity extends BaseDnsActivity {
Button link = (Button) findViewById(R.id.event_view_link);
title.setText(e.title);
description.setText(e.description);
location.setText(e.location);
datetime.setText(e.date);
StringBuilder sb = new StringBuilder();
if (e.description.length() > 0) {
sb.append("<b>");
sb.append(e.description);
sb.append("</b><br/><br/>");
}
if (e.text.length() > 0) {
sb.append(e.text);
}
description.setText(Html.fromHtml(sb.toString()));
if (e.id > 0) { // if id exists and seems legit
link.setVisibility(View.VISIBLE);
link.setOnClickListener(new OnClickListener() {
@@ -24,6 +24,7 @@ import com.studentersamfundet.app.XmlParser;
public class ProgramListActivity extends BaseDnsActivity {
public static final String feedURL = "http://dl.dropbox.com/u/293287/test.xml";
//public static final String feedURL = "http://studentersamfundet.no/";
public static final String localURL = "/data/com.studentersamfundet.app/files/dns_events";
public static FeedFetcher feed = new FeedFetcher();
public static XmlParser parser = new XmlParser();