ArrayList values = new ArrayList();
for (int i = 0; (ratings != null) && (i < ratings.size()); i++) {
try {
Element rat = (Element) ratings.get(i);
values.add(new Rating(rat.getAttributeValue("scheme"),
rat.getText()));
} catch (Exception ex) {
LOG.log(Level.WARNING, "Exception parsing rating tag.", ex);
}
}
md.setRatings((Rating[]) values.toArray(new Rating[values.size()]));
}
// text
{
List texts = e.getChildren("text", getNS());
ArrayList values = new ArrayList();
for (int i = 0; (texts != null) && (i < texts.size()); i++) {
try {
Element text = (Element) texts.get(i);
Time start = (text.getAttributeValue("start") == null)
? null : new Time(text.getAttributeValue("start"));
Time end = (text.getAttributeValue("end") == null) ? null
: new Time(text.getAttributeValue(
"end"));
values.add(new Text(text.getAttributeValue("type"),
text.getTextTrim(), start, end));
} catch (Exception ex) {
LOG.log(Level.WARNING, "Exception parsing text tag.", ex);
}
}
md.setText((Text[]) values.toArray(new Text[values.size()]));
}
// thumbnails
{
List thumbnails = e.getChildren("thumbnail", getNS());
ArrayList values = new ArrayList();
for (int i = 0; (thumbnails != null) && (i < thumbnails.size());
i++) {
try {
Element thumb = (Element) thumbnails.get(i);
Time t = (thumb.getAttributeValue("time") == null) ? null
: new Time(thumb.getAttributeValue(
"time"));
Integer width = (thumb.getAttributeValue("width") == null)
? null : new Integer(thumb.getAttributeValue("width"));
Integer height = (thumb.getAttributeValue("height") == null)
? null : new Integer(thumb.getAttributeValue("height"));
values.add(new Thumbnail(
new URI(thumb.getAttributeValue("url")), width,
height, t));
} catch (Exception ex) {
LOG.log(Level.WARNING, "Exception parsing thumbnail tag.",
ex);
}
}
md.setThumbnail((Thumbnail[]) values.toArray(
new Thumbnail[values.size()]));
}
// title
{
Element title = e.getChild("title", getNS());
if (title != null) {
md.setTitle(title.getText());
md.setTitleType(title.getAttributeValue("type"));
}
}
// restrictions
{
List restrictions = e.getChildren("restriction", getNS());
ArrayList values = new ArrayList();
for (int i = 0; i < restrictions.size(); i++) {
Element r = (Element) restrictions.get(i);
Restriction.Type type = null;
if (r.getAttributeValue("type").equalsIgnoreCase("uri")) {
type = Restriction.Type.URI;
} else if (r.getAttributeValue("type").equalsIgnoreCase("country")) {
type = Restriction.Type.COUNTRY;
}
Restriction.Relationship relationship = null;
if (r.getAttributeValue("relationship").equalsIgnoreCase("allow")) {
relationship = Restriction.Relationship.ALLOW;
} else if (r.getAttributeValue("relationship").equalsIgnoreCase("deny")) {
relationship = Restriction.Relationship.DENY;
}
Restriction value = new Restriction(relationship, type,
r.getTextTrim());
values.add(value);
}
md.setRestrictions((Restriction[]) values.toArray(
new Restriction[values.size()]));
}
// handle adult
{
Element adult = e.getChild("adult", getNS());
if ((adult != null) && (md.getRatings().length == 0)) {
Rating[] r = new Rating[1];
if (adult.getTextTrim().equals("true")) {
r[0] = new Rating("urn:simple", "adult");
} else {
r[0] = new Rating("urn:simple", "nonadult");
}
md.setRatings(r);
}
}