Created
February 26, 2010 04:06
-
-
Save eed3si9n/315381 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package footprint | |
abstract class DataModel | |
case class CategoryTags(categoryTag: String*) extends DataModel { | |
} | |
object CategoryTags { | |
def fromXML(node: scala.xml.Node): CategoryTags = | |
CategoryTags((node \ "categoryTag").toList.map(_.text): _*) | |
} | |
case class Reviews(Review: Review*) extends DataModel { | |
} | |
object Reviews { | |
def fromXML(node: scala.xml.Node): Reviews = | |
Reviews((node \ "Review").map(Review.fromXML(_)): _*) | |
} | |
case class VolunteerOpportunities(VolunteerOpportunity: VolunteerOpportunity*) extends DataModel { | |
} | |
object VolunteerOpportunities { | |
def fromXML(node: scala.xml.Node): VolunteerOpportunities = | |
VolunteerOpportunities((node \ "VolunteerOpportunity").map(VolunteerOpportunity.fromXML(_)): _*) | |
} | |
case class Locations(location: LocationType*) extends DataModel { | |
} | |
object Locations { | |
def fromXML(node: scala.xml.Node): Locations = | |
Locations((node \ "location").map(LocationType.fromXML(_)): _*) | |
} | |
case class Review(reviewID: Option[String], | |
organizationID: Option[String], | |
volunteerOpportunityID: Option[String], | |
rating: Option[BigDecimal], | |
ratingMaximum: Option[BigDecimal], | |
text: Option[String], | |
reviewerName: Option[String], | |
reviewerID: Option[String], | |
reviewerRole: Option[String], | |
lastUpdated: Option[DateTimeOlsonDefaultPacific]) extends DataModel { | |
} | |
object Review { | |
def fromXML(node: scala.xml.Node): Review = | |
Review((node \ "reviewID").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "organizationID").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "volunteerOpportunityID").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "rating").headOption match { | |
case None => None | |
case Some(x) => Some(BigDecimal(x.text)) | |
}, | |
(node \ "ratingMaximum").headOption match { | |
case None => None | |
case Some(x) => Some(BigDecimal(x.text)) | |
}, | |
(node \ "text").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "reviewerName").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "reviewerID").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "reviewerRole").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "lastUpdated").headOption match { | |
case None => None | |
case Some(x) => Some(DateTimeOlsonDefaultPacific.fromXML(x)) | |
}) | |
} | |
case class VolunteerHubOrganizationIDs(volunteerHubOrganizationID: String*) extends DataModel { | |
} | |
object VolunteerHubOrganizationIDs { | |
def fromXML(node: scala.xml.Node): VolunteerHubOrganizationIDs = | |
VolunteerHubOrganizationIDs((node \ "volunteerHubOrganizationID").toList.map(_.text): _*) | |
} | |
case class DateTimeOlsonDefaultPacific(value: java.util.Calendar, | |
olsonTZ: String) extends DataModel { | |
} | |
object DateTimeOlsonDefaultPacific { | |
def fromXML(node: scala.xml.Node): DateTimeOlsonDefaultPacific = | |
DateTimeOlsonDefaultPacific(Helper.toCalendar(node.text), | |
(node \ "@olsonTZ").headOption match { | |
case None => "America/Los_Angeles" | |
case Some(x) => x.text | |
}) | |
} | |
case class LocationType(virtual: Option[String], | |
name: Option[String], | |
streetAddress1: Option[String], | |
streetAddress2: Option[String], | |
streetAddress3: Option[String], | |
city: Option[String], | |
region: Option[String], | |
postalCode: Option[String], | |
country: Option[String], | |
latitude: Option[BigDecimal], | |
longitude: Option[BigDecimal], | |
directions: Option[String]) extends DataModel { | |
} | |
object LocationType { | |
def fromXML(node: scala.xml.Node): LocationType = | |
LocationType((node \ "virtual").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "name").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "streetAddress1").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "streetAddress2").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "streetAddress3").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "city").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "region").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "postalCode").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "country").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "latitude").headOption match { | |
case None => None | |
case Some(x) => Some(BigDecimal(x.text)) | |
}, | |
(node \ "longitude").headOption match { | |
case None => None | |
case Some(x) => Some(BigDecimal(x.text)) | |
}, | |
(node \ "directions").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}) | |
} | |
case class Organizations(Organization: Organization*) extends DataModel { | |
} | |
object Organizations { | |
def fromXML(node: scala.xml.Node): Organizations = | |
Organizations((node \ "Organization").map(Organization.fromXML(_)): _*) | |
} | |
case class FootprintFeed(FeedInfo: Option[FeedInfo], | |
Organizations: Option[Organizations], | |
VolunteerOpportunities: Option[VolunteerOpportunities], | |
Reviews: Option[Reviews], | |
schemaVersion: BigDecimal) extends DataModel { | |
} | |
object FootprintFeed { | |
def fromXML(node: scala.xml.Node): FootprintFeed = | |
FootprintFeed((node \ "FeedInfo").headOption match { | |
case None => None | |
case Some(x) => Some(FeedInfo.fromXML(x)) | |
}, | |
(node \ "Organizations").headOption match { | |
case None => None | |
case Some(x) => Some(Organizations.fromXML(x)) | |
}, | |
(node \ "VolunteerOpportunities").headOption match { | |
case None => None | |
case Some(x) => Some(VolunteerOpportunities.fromXML(x)) | |
}, | |
(node \ "Reviews").headOption match { | |
case None => None | |
case Some(x) => Some(Reviews.fromXML(x)) | |
}, | |
BigDecimal("0.1")) | |
} | |
case class TimeOlson(value: java.util.Calendar, | |
olsonTZ: String) extends DataModel { | |
} | |
object TimeOlson { | |
def fromXML(node: scala.xml.Node): TimeOlson = | |
TimeOlson(Helper.toCalendar(node.text), | |
(node \ "@olsonTZ").headOption match { | |
case None => "" | |
case Some(x) => x.text | |
}) | |
} | |
case class SponsoringOrganizationIDs(sponsoringOrganizationID: String*) extends DataModel { | |
} | |
object SponsoringOrganizationIDs { | |
def fromXML(node: scala.xml.Node): SponsoringOrganizationIDs = | |
SponsoringOrganizationIDs((node \ "sponsoringOrganizationID").toList.map(_.text): _*) | |
} | |
case class DateTimeDurations(dateTimeDuration: DateTimeDurationType*) extends DataModel { | |
} | |
object DateTimeDurations { | |
def fromXML(node: scala.xml.Node): DateTimeDurations = | |
DateTimeDurations((node \ "dateTimeDuration").map(DateTimeDurationType.fromXML(_)): _*) | |
} | |
case class Organization(organizationID: Option[String], | |
nationalEIN: Option[String], | |
guidestarID: Option[Int], | |
name: Option[String], | |
missionStatement: Option[String], | |
description: Option[String], | |
location: Option[LocationType], | |
phone: Option[String], | |
fax: Option[String], | |
email: Option[String], | |
organizationURL: Option[String], | |
donateURL: Option[String], | |
logoURL: Option[String], | |
detailURL: Option[String]) extends DataModel { | |
} | |
object Organization { | |
def fromXML(node: scala.xml.Node): Organization = | |
Organization((node \ "organizationID").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "nationalEIN").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "guidestarID").headOption match { | |
case None => None | |
case Some(x) => Some(x.text.toInt) | |
}, | |
(node \ "name").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "missionStatement").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "description").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "location").headOption match { | |
case None => None | |
case Some(x) => Some(LocationType.fromXML(x)) | |
}, | |
(node \ "phone").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "fax").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "email").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "organizationURL").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "donateURL").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "logoURL").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "detailURL").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}) | |
} | |
case class AudienceTags(audienceTag: String*) extends DataModel { | |
} | |
object AudienceTags { | |
def fromXML(node: scala.xml.Node): AudienceTags = | |
AudienceTags((node \ "audienceTag").toList.map(_.text): _*) | |
} | |
case class DateTimeDurationType(openEnded: Option[String], | |
startDate: Option[java.util.Calendar], | |
endDate: Option[java.util.Calendar], | |
iCalRecurrence: Option[String], | |
duration: Option[javax.xml.datatype.Duration], | |
startTime: Option[TimeOlson], | |
endTime: Option[TimeOlson], | |
timeFlexible: Option[String], | |
commitmentHoursPerWeek: Option[BigDecimal]) extends DataModel { | |
} | |
object DateTimeDurationType { | |
def fromXML(node: scala.xml.Node): DateTimeDurationType = | |
DateTimeDurationType((node \ "openEnded").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "startDate").headOption match { | |
case None => None | |
case Some(x) => Some(Helper.toCalendar(x.text)) | |
}, | |
(node \ "endDate").headOption match { | |
case None => None | |
case Some(x) => Some(Helper.toCalendar(x.text)) | |
}, | |
(node \ "iCalRecurrence").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "duration").headOption match { | |
case None => None | |
case Some(x) => Some(Helper.toDuration(x.text)) | |
}, | |
(node \ "startTime").headOption match { | |
case None => None | |
case Some(x) => Some(TimeOlson.fromXML(x)) | |
}, | |
(node \ "endTime").headOption match { | |
case None => None | |
case Some(x) => Some(TimeOlson.fromXML(x)) | |
}, | |
(node \ "timeFlexible").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "commitmentHoursPerWeek").headOption match { | |
case None => None | |
case Some(x) => Some(BigDecimal(x.text)) | |
}) | |
} | |
case class VolunteerOpportunity(volunteerOpportunityID: Option[String], | |
sponsoringOrganizationIDs: Option[SponsoringOrganizationIDs], | |
volunteerHubOrganizationIDs: Option[VolunteerHubOrganizationIDs], | |
title: Option[String], | |
abstractValue: Option[String], | |
volunteersNeeded: Option[Int], | |
rsvpCount: Option[Int], | |
dateTimeDurations: Option[DateTimeDurations], | |
locations: Option[Locations], | |
paid: Option[String], | |
audienceTags: Option[AudienceTags], | |
categoryTags: Option[CategoryTags], | |
minimumAge: Option[Int], | |
sexRestrictedTo: Option[String], | |
skills: Option[String], | |
contactName: Option[String], | |
contactPhone: Option[String], | |
contactEmail: Option[String], | |
detailURL: Option[String], | |
language: Option[String], | |
description: Option[String], | |
lastUpdated: Option[DateTimeOlsonDefaultPacific], | |
expires: Option[DateTimeOlsonDefaultPacific]) extends DataModel { | |
} | |
object VolunteerOpportunity { | |
def fromXML(node: scala.xml.Node): VolunteerOpportunity = | |
VolunteerOpportunity((node \ "volunteerOpportunityID").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "sponsoringOrganizationIDs").headOption match { | |
case None => None | |
case Some(x) => Some(SponsoringOrganizationIDs.fromXML(x)) | |
}, | |
(node \ "volunteerHubOrganizationIDs").headOption match { | |
case None => None | |
case Some(x) => Some(VolunteerHubOrganizationIDs.fromXML(x)) | |
}, | |
(node \ "title").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "abstract").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "volunteersNeeded").headOption match { | |
case None => None | |
case Some(x) => Some(x.text.toInt) | |
}, | |
(node \ "rsvpCount").headOption match { | |
case None => None | |
case Some(x) => Some(x.text.toInt) | |
}, | |
(node \ "dateTimeDurations").headOption match { | |
case None => None | |
case Some(x) => Some(DateTimeDurations.fromXML(x)) | |
}, | |
(node \ "locations").headOption match { | |
case None => None | |
case Some(x) => Some(Locations.fromXML(x)) | |
}, | |
(node \ "paid").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "audienceTags").headOption match { | |
case None => None | |
case Some(x) => Some(AudienceTags.fromXML(x)) | |
}, | |
(node \ "categoryTags").headOption match { | |
case None => None | |
case Some(x) => Some(CategoryTags.fromXML(x)) | |
}, | |
(node \ "minimumAge").headOption match { | |
case None => None | |
case Some(x) => Some(x.text.toInt) | |
}, | |
(node \ "sexRestrictedTo").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "skills").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "contactName").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "contactPhone").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "contactEmail").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "detailURL").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "language").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "description").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "lastUpdated").headOption match { | |
case None => None | |
case Some(x) => Some(DateTimeOlsonDefaultPacific.fromXML(x)) | |
}, | |
(node \ "expires").headOption match { | |
case None => None | |
case Some(x) => Some(DateTimeOlsonDefaultPacific.fromXML(x)) | |
}) | |
} | |
case class FeedInfo(providerID: Option[String], | |
providerName: Option[String], | |
feedID: Option[String], | |
createdDateTime: Option[DateTimeOlsonDefaultPacific], | |
providerURL: Option[String], | |
termsOfUse: Option[String], | |
description: Option[String]) extends DataModel { | |
} | |
object FeedInfo { | |
def fromXML(node: scala.xml.Node): FeedInfo = | |
FeedInfo((node \ "providerID").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "providerName").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "feedID").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "createdDateTime").headOption match { | |
case None => None | |
case Some(x) => Some(DateTimeOlsonDefaultPacific.fromXML(x)) | |
}, | |
(node \ "providerURL").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "termsOfUse").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}, | |
(node \ "description").headOption match { | |
case None => None | |
case Some(x) => Some(x.text) | |
}) | |
} | |
class Calendar extends java.util.GregorianCalendar { | |
override def toString: String = Helper.toString(this) | |
} | |
object Calendar { | |
def apply(value: String): Calendar = Helper.toCalendar(value) | |
def unapply(value: Calendar): Option[String] = Some(Helper.toString(value)) | |
} | |
object Helper { | |
lazy val typeFactory = javax.xml.datatype.DatatypeFactory.newInstance() | |
def toCalendar(value: String) = { | |
val gregorian = typeFactory.newXMLGregorianCalendar(value).toGregorianCalendar | |
val cal = new Calendar() | |
for (i <- 0 to java.util.Calendar.FIELD_COUNT - 1) | |
if (gregorian.isSet(i)) | |
cal.set(i, gregorian.get(i)) | |
cal | |
} | |
def toString(value: Calendar) = { | |
val xmlGregorian = typeFactory.newXMLGregorianCalendar(value) | |
xmlGregorian.toString | |
} | |
def toDuration(value: String) = | |
typeFactory.newDuration(value) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment