* Examines every date field in a Resource and creates a distribution of years.
*
* @return URL representing the Google URL
*/
private URL buildDateGraph() throws IOException {
Distribution distribution = new Distribution();
for (Resource resource : getResources()) {
// Examine the ddms:dates element (optional field with optional attributes)
// Ignores ddms:DateHourMinType dates, which were introduced in DDMS 4.1, to simplify example
Dates dates = resource.getDates();
if (dates != null) {
if (dates.getCreated() != null)
distribution.incrementCount(String.valueOf(dates.getCreated().getYear()));
if (dates.getPosted() != null)
distribution.incrementCount(String.valueOf(dates.getPosted().getYear()));
if (dates.getValidTil() != null)
distribution.incrementCount(String.valueOf(dates.getValidTil().getYear()));
if (dates.getInfoCutOff() != null)
distribution.incrementCount(String.valueOf(dates.getInfoCutOff().getYear()));
if (dates.getApprovedOn() != null)
distribution.incrementCount(String.valueOf(dates.getApprovedOn().getYear()));
if (dates.getReceivedOn() != null)
distribution.incrementCount(String.valueOf(dates.getReceivedOn().getYear()));
}
// Resource createDate (required field in 3.0, 4.0.1, and 4.1, optional in 2.0)
if (resource.getCreateDate() != null)
distribution.incrementCount(String.valueOf(resource.getCreateDate().getYear()));
// ddms:temporalCoverage (optional field)
// getStart() returns the date if present. getStartString() returns the XML format or
// the two allowed strings, Not Applicable, and Unknown.
List<TemporalCoverage> timePeriods = resource.getTemporalCoverages();
for (TemporalCoverage timePeriod : timePeriods) {
if (timePeriod.getStart() != null)
distribution.incrementCount(String.valueOf(timePeriod.getStart().getYear()));
if (timePeriod.getEnd() != null)
distribution.incrementCount(String.valueOf(timePeriod.getEnd().getYear()));
}
}
return (buildPieGraphURL("DDMS%20Date%20Distribution", distribution, PIE_GRAPH));
}