List of usage examples for org.jdom2 Element getAttributeValue
public String getAttributeValue(final String attname)
This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.
From source file:com.ohnosequences.bio4j.tools.ExtractCitationsCommentsSamples.java
License:Open Source License
public static void main(String[] args) throws FileNotFoundException, IOException, Exception { if (args.length != 1) { System.out.println("El programa espera un parametro: \n" + "1. Nombre del archivo xml a importar \n"); } else {/*from w w w . ja va 2 s .c o m*/ File inFile = new File(args[0]); Map<String, String> citationsTypesMap = new HashMap<String, String>(); Map<String, String> commentsTypesMap = new HashMap<String, String>(); BufferedWriter citationsOutBuff = new BufferedWriter(new FileWriter(new File("citations.xml"))); BufferedWriter commentsOutBuff = new BufferedWriter(new FileWriter(new File("comments.xml"))); citationsOutBuff.write("<citations>\n"); commentsOutBuff.write("<comments>\n"); BufferedReader reader = new BufferedReader(new FileReader(inFile)); String line = null; StringBuilder entryStBuilder = new StringBuilder(); while ((line = reader.readLine()) != null) { if (line.trim().startsWith("<entry")) { while (!line.trim().startsWith("</entry>")) { entryStBuilder.append(line); line = reader.readLine(); } //linea final del organism entryStBuilder.append(line); //System.out.println("organismStBuilder.toString() = " + organismStBuilder.toString()); XMLElement entryXMLElem = new XMLElement(entryStBuilder.toString()); entryStBuilder.delete(0, entryStBuilder.length()); List<Element> referenceList = entryXMLElem.asJDomElement().getChildren("reference"); for (Element reference : referenceList) { List<Element> citationsList = reference.getChildren("citation"); for (Element citation : citationsList) { if (citationsTypesMap.get(citation.getAttributeValue("type")) == null) { XMLElement citationXML = new XMLElement(citation); System.out.println("citation = " + citationXML); citationsTypesMap.put(citation.getAttributeValue("type"), citationXML.toString()); } } } List<Element> commentsList = entryXMLElem.asJDomElement().getChildren("comment"); for (Element comment : commentsList) { if (commentsTypesMap.get(comment.getAttributeValue("type")) == null) { XMLElement commentXML = new XMLElement(comment); System.out.println("comment = " + commentXML); commentsTypesMap.put(comment.getAttributeValue("type"), commentXML.toString()); } } } } Set<String> keys = citationsTypesMap.keySet(); for (String key : keys) { citationsOutBuff.write(citationsTypesMap.get(key)); } citationsOutBuff.write("</citations>\n"); citationsOutBuff.close(); System.out.println("Citations file created successfully!"); Set<String> keysComments = commentsTypesMap.keySet(); for (String key : keysComments) { commentsOutBuff.write(commentsTypesMap.get(key)); } commentsOutBuff.write("</comments>\n"); commentsOutBuff.close(); System.out.println("Comments file created successfully!"); } }
From source file:com.ohnosequences.bio4j.tools.ExtractFeaturesSamples.java
License:Open Source License
public static void main(String[] args) throws FileNotFoundException, IOException, Exception { if (args.length != 1) { System.out.println("El programa espera un parametro: \n" + "1. Nombre del archivo xml a importar \n"); } else {/*from w w w.j av a 2 s.c om*/ File inFile = new File(args[0]); Map<String, String> featureTypesMap = new HashMap<String, String>(); BufferedWriter outBuff = new BufferedWriter(new FileWriter(new File("features.xml"))); outBuff.write("<features>\n"); BufferedReader reader = new BufferedReader(new FileReader(inFile)); String line = null; StringBuilder entryStBuilder = new StringBuilder(); while ((line = reader.readLine()) != null) { if (line.trim().startsWith("<entry")) { while (!line.trim().startsWith("</entry>")) { entryStBuilder.append(line); line = reader.readLine(); } //linea final del organism entryStBuilder.append(line); //System.out.println("organismStBuilder.toString() = " + organismStBuilder.toString()); XMLElement entryXMLElem = new XMLElement(entryStBuilder.toString()); entryStBuilder.delete(0, entryStBuilder.length()); List<Element> featuresList = entryXMLElem.asJDomElement().getChildren("feature"); for (Element element : featuresList) { if (featureTypesMap.get(element.getAttributeValue("type")) == null) { XMLElement feature = new XMLElement(element); System.out.println("feature = " + feature); featureTypesMap.put(element.getAttributeValue("type"), feature.toString()); } } } } Set<String> keys = featureTypesMap.keySet(); for (String key : keys) { outBuff.write(featureTypesMap.get(key)); } outBuff.write("</features>\n"); outBuff.close(); System.out.println("Features file created successfully!"); } }
From source file:com.ohnosequences.bio4j.tools.uniprot.ExtractCitationsCommentsSamples.java
License:Open Source License
public static void main(String[] args) { if (args.length != 1) { System.out.println("This program expects the following parameters: \n" + "1. Input XML file \n"); } else {//w w w.j a v a 2s. c om BufferedWriter citationsOutBuff = null; try { File inFile = new File(args[0]); Map<String, String> citationsTypesMap = new HashMap<String, String>(); Map<String, String> commentsTypesMap = new HashMap<String, String>(); citationsOutBuff = new BufferedWriter(new FileWriter(new File("citations.xml"))); BufferedWriter commentsOutBuff = new BufferedWriter(new FileWriter(new File("comments.xml"))); citationsOutBuff.write("<citations>\n"); commentsOutBuff.write("<comments>\n"); BufferedReader reader = new BufferedReader(new FileReader(inFile)); String line = null; StringBuilder entryStBuilder = new StringBuilder(); while ((line = reader.readLine()) != null) { if (line.trim().startsWith("<entry")) { while (!line.trim().startsWith("</entry>")) { entryStBuilder.append(line); line = reader.readLine(); } //linea final del organism entryStBuilder.append(line); //System.out.println("organismStBuilder.toString() = " + organismStBuilder.toString()); XMLElement entryXMLElem = new XMLElement(entryStBuilder.toString()); entryStBuilder.delete(0, entryStBuilder.length()); List<Element> referenceList = entryXMLElem.asJDomElement().getChildren("reference"); for (Element reference : referenceList) { List<Element> citationsList = reference.getChildren("citation"); for (Element citation : citationsList) { if (citationsTypesMap.get(citation.getAttributeValue("type")) == null) { XMLElement citationXML = new XMLElement(citation); System.out.println("citation = " + citationXML); citationsTypesMap.put(citation.getAttributeValue("type"), citationXML.toString()); } } } List<Element> commentsList = entryXMLElem.asJDomElement().getChildren("comment"); for (Element comment : commentsList) { if (commentsTypesMap.get(comment.getAttributeValue("type")) == null) { XMLElement commentXML = new XMLElement(comment); System.out.println("comment = " + commentXML); commentsTypesMap.put(comment.getAttributeValue("type"), commentXML.toString()); } } } } Set<String> keys = citationsTypesMap.keySet(); for (String key : keys) { citationsOutBuff.write(citationsTypesMap.get(key)); } citationsOutBuff.write("</citations>\n"); citationsOutBuff.close(); System.out.println("Citations file created successfully!"); Set<String> keysComments = commentsTypesMap.keySet(); for (String key : keysComments) { commentsOutBuff.write(commentsTypesMap.get(key)); } commentsOutBuff.write("</comments>\n"); commentsOutBuff.close(); System.out.println("Comments file created successfully!"); } catch (Exception ex) { e.xprintStackTrace(); } finally { try { citationsOutBuff.close(); } catch (IOException ex) { ex.printStackTrace(); } } } }
From source file:com.ohnosequences.bio4j.tools.uniprot.ExtractFeaturesSamples.java
License:Open Source License
public static void main(String[] args) { if (args.length != 1) { System.out.println("This program expects the following parameters: \n" + "1. Input XML file \n"); } else {// w ww . j av a 2s.com BufferedWriter outBuff = null; try { File inFile = new File(args[0]); Map<String, String> featureTypesMap = new HashMap<String, String>(); outBuff = new BufferedWriter(new FileWriter(new File("features.xml"))); outBuff.write("<features>\n"); BufferedReader reader = new BufferedReader(new FileReader(inFile)); String line = null; StringBuilder entryStBuilder = new StringBuilder(); while ((line = reader.readLine()) != null) { if (line.trim().startsWith("<entry")) { while (!line.trim().startsWith("</entry>")) { entryStBuilder.append(line); line = reader.readLine(); } //linea final del organism entryStBuilder.append(line); //System.out.println("organismStBuilder.toString() = " + organismStBuilder.toString()); XMLElement entryXMLElem = new XMLElement(entryStBuilder.toString()); entryStBuilder.delete(0, entryStBuilder.length()); List<Element> featuresList = entryXMLElem.asJDomElement().getChildren("feature"); for (Element element : featuresList) { if (featureTypesMap.get(element.getAttributeValue("type")) == null) { XMLElement feature = new XMLElement(element); System.out.println("feature = " + feature); featureTypesMap.put(element.getAttributeValue("type"), feature.toString()); } } } } Set<String> keys = featureTypesMap.keySet(); for (String key : keys) { outBuff.write(featureTypesMap.get(key)); } outBuff.write("</features>\n"); outBuff.close(); System.out.println("Features file created successfully!"); } catch (Exception ex) { ex.printStackTrace(); } finally { try { outBuff.close(); } catch (IOException ex) { ex.printStackTrace(); } } } }
From source file:com.rhythm.louie.server.AccessManager.java
License:Apache License
protected static void loadGroups(Element groups) { for (Element group : groups.getChildren()) { String name = group.getAttributeValue(GROUP_NAME).toLowerCase(); if (ADMIN.equals(name)) { adminUsers.clear(); //to allow re-loading from a default set by a specific louie.xml impl wild = false;/*from w w w .ja v a2s.c o m*/ for (Element user : group.getChildren()) { String u = user.getTextTrim(); if (WILDCARD.equals(u)) { wild = true; break; } adminUsers.add(user.getTextTrim()); } } else { Set<String> users = new HashSet<>(); for (Element user : group.getChildren()) { users.add(user.getTextTrim()); } groupUsers.put(name, users); } } }
From source file:com.rhythm.louie.server.LouieProperties.java
License:Apache License
private static void processServiceLayers(Element layers, ServiceProperties props) { for (Element layer : layers.getChildren()) { String layerName = layer.getName().toLowerCase(); switch (layerName) { case LAYER: props.addLayer(new CustomServiceLayer(layer.getAttributeValue("class"))); break; case LAYER_DAO: props.addLayer(AnnotatedServiceLayer.DAO); break; case LAYER_CACHE: props.addLayer(AnnotatedServiceLayer.CACHE); break; case LAYER_ROUTER: props.addLayer(AnnotatedServiceLayer.ROUTER); break; case LAYER_REMOTE: String server = layer.getAttributeValue(SERVER); String host = layer.getAttributeValue(HOST); String gateway = layer.getAttributeValue(GATEWAY); String port = layer.getAttributeValue(PORT); if (server != null) { props.addLayer(new RemoteServiceLayer(server)); } else if (host != null && gateway != null && port != null) { props.addLayer(new RemoteServiceLayer(host, gateway, Integer.parseInt(port))); } else { String defaultServer = ServiceProperties.getDefaultRemoteServer(); if (defaultServer == null) { LoggerFactory.getLogger(LouieProperties.class).error( "Failed to configure remote layer for service {}. Check configs.", props.getName()); }/*from ww w . j a va2 s .com*/ props.addLayer(new RemoteServiceLayer(defaultServer)); } break; default: LoggerFactory.getLogger(LouieProperties.class).warn("Unkown layer:{}", layerName); } } }
From source file:com.rometools.modules.base.io.CustomTagParser.java
License:Open Source License
@Override public Module parse(final Element element, final Locale locale) { final CustomTags module = new CustomTagsImpl(); final ArrayList<CustomTag> tags = new ArrayList<CustomTag>(); final List<Element> elements = element.getChildren(); final Iterator<Element> it = elements.iterator(); while (it.hasNext()) { final Element child = it.next(); if (child.getNamespace().equals(NS)) { final String type = child.getAttributeValue("type"); try { if (type == null) { continue; } else if (type.equals("string")) { tags.add(new CustomTagImpl(child.getName(), child.getText())); } else if (type.equals("int")) { tags.add(new CustomTagImpl(child.getName(), new Integer(child.getTextTrim()))); } else if (type.equals("float")) { tags.add(new CustomTagImpl(child.getName(), new Float(child.getTextTrim()))); } else if (type.equals("intUnit")) { tags.add(new CustomTagImpl(child.getName(), new IntUnit(child.getTextTrim()))); } else if (type.equals("floatUnit")) { tags.add(new CustomTagImpl(child.getName(), new FloatUnit(child.getTextTrim()))); } else if (type.equals("date")) { try { tags.add(new CustomTagImpl(child.getName(), new ShortDate(GoogleBaseParser.SHORT_DT_FMT.parse(child.getTextTrim())))); } catch (final ParseException e) { LOG.warn("Unable to parse date type on " + child.getName(), e); }//from www .jav a 2 s . co m } else if (type.equals("dateTime")) { try { tags.add(new CustomTagImpl(child.getName(), GoogleBaseParser.LONG_DT_FMT.parse(child.getTextTrim()))); } catch (final ParseException e) { LOG.warn("Unable to parse date type on " + child.getName(), e); } } else if (type.equals("dateTimeRange")) { try { tags.add(new CustomTagImpl(child.getName(), new DateTimeRange( GoogleBaseParser.LONG_DT_FMT.parse( child.getChild("start", CustomTagParser.NS).getText().trim()), GoogleBaseParser.LONG_DT_FMT.parse( child.getChild("end", CustomTagParser.NS).getText().trim())))); } catch (final Exception e) { LOG.warn("Unable to parse date type on " + child.getName(), e); } } else if (type.equals("url")) { try { tags.add(new CustomTagImpl(child.getName(), new URL(child.getTextTrim()))); } catch (final MalformedURLException e) { LOG.warn("Unable to parse URL type on " + child.getName(), e); } } else if (type.equals("boolean")) { tags.add( new CustomTagImpl(child.getName(), new Boolean(child.getTextTrim().toLowerCase()))); } else if (type.equals("location")) { tags.add(new CustomTagImpl(child.getName(), new CustomTagImpl.Location(child.getText()))); } else { throw new Exception("Unknown type: " + type); } } catch (final Exception e) { LOG.warn("Unable to parse type on " + child.getName(), e); } } } module.setValues(tags); return module; }
From source file:com.rometools.modules.itunes.io.ITunesParser.java
License:Open Source License
@Override public com.rometools.rome.feed.module.Module parse(final Element element, final Locale locale) { AbstractITunesObject module = null;// w w w. j av a 2 s . c o m if (element.getName().equals("channel")) { final FeedInformationImpl feedInfo = new FeedInformationImpl(); module = feedInfo; // Now I am going to get the channel specific tags final Element owner = element.getChild("owner", ns); if (owner != null) { final Element name = owner.getChild("name", ns); if (name != null) { feedInfo.setOwnerName(name.getValue().trim()); } final Element email = owner.getChild("email", ns); if (email != null) { feedInfo.setOwnerEmailAddress(email.getValue().trim()); } } final Element image = element.getChild("image", ns); if (image != null && image.getAttributeValue("href") != null) { try { final URL imageURL = new URL(image.getAttributeValue("href").trim()); feedInfo.setImage(imageURL); } catch (final MalformedURLException e) { LOG.debug("Malformed URL Exception reading itunes:image tag: {}", image.getAttributeValue("href")); } } final List<Element> categories = element.getChildren("category", ns); for (final Element element2 : categories) { final Element category = element2; if (category != null && category.getAttribute("text") != null) { final Category cat = new Category(); cat.setName(category.getAttribute("text").getValue().trim()); final Element subcategory = category.getChild("category", ns); if (subcategory != null && subcategory.getAttribute("text") != null) { final Subcategory subcat = new Subcategory(); subcat.setName(subcategory.getAttribute("text").getValue().trim()); cat.setSubcategory(subcat); } feedInfo.getCategories().add(cat); } } } else if (element.getName().equals("item")) { final EntryInformationImpl entryInfo = new EntryInformationImpl(); module = entryInfo; // Now I am going to get the item specific tags final Element duration = element.getChild("duration", ns); if (duration != null && duration.getValue() != null) { final Duration dur = new Duration(duration.getValue().trim()); entryInfo.setDuration(dur); } } if (module != null) { // All these are common to both Channel and Item final Element author = element.getChild("author", ns); if (author != null && author.getText() != null) { module.setAuthor(author.getText()); } final Element block = element.getChild("block", ns); if (block != null) { module.setBlock(true); } final Element explicit = element.getChild("explicit", ns); if (explicit != null && explicit.getValue() != null && explicit.getValue().trim().equalsIgnoreCase("yes")) { module.setExplicit(true); } final Element keywords = element.getChild("keywords", ns); if (keywords != null) { final StringTokenizer tok = new StringTokenizer(getXmlInnerText(keywords).trim(), ","); final String[] keywordsArray = new String[tok.countTokens()]; for (int i = 0; tok.hasMoreTokens(); i++) { keywordsArray[i] = tok.nextToken(); } module.setKeywords(keywordsArray); } final Element subtitle = element.getChild("subtitle", ns); if (subtitle != null) { module.setSubtitle(subtitle.getTextTrim()); } final Element summary = element.getChild("summary", ns); if (summary != null) { module.setSummary(summary.getTextTrim()); } } return module; }
From source file:com.rometools.modules.mediarss.io.MediaModuleParser.java
License:Open Source License
private MediaContent[] parseContent(final Element e) { final List<Element> contents = e.getChildren("content", getNS()); final ArrayList<MediaContent> values = new ArrayList<MediaContent>(); try {//from w ww . jav a 2 s.c o m for (int i = 0; contents != null && i < contents.size(); i++) { final Element content = contents.get(i); MediaContent mc = null; if (content.getAttributeValue("url") != null) { try { mc = new MediaContent( new UrlReference(new URI(content.getAttributeValue("url").replace(' ', '+')))); mc.setPlayer(parsePlayer(content)); } catch (final Exception ex) { LOG.warn("Exception parsing content tag.", ex); } } else { mc = new MediaContent(parsePlayer(content)); } if (mc != null) { values.add(mc); try { if (content.getAttributeValue("channels") != null) { mc.setAudioChannels(Integer.valueOf(content.getAttributeValue("channels"))); } } catch (final Exception ex) { LOG.warn("Exception parsing content tag.", ex); } try { if (content.getAttributeValue("bitrate") != null) { mc.setBitrate(Float.valueOf(content.getAttributeValue("bitrate"))); } } catch (final Exception ex) { LOG.warn("Exception parsing content tag.", ex); } try { if (content.getAttributeValue("duration") != null) { mc.setDuration(Longs.parseDecimal(content.getAttributeValue("duration"))); } } catch (final Exception ex) { LOG.warn("Exception parsing content tag.", ex); } mc.setMedium(content.getAttributeValue("medium")); final String expression = content.getAttributeValue("expression"); if (expression != null) { if (expression.equalsIgnoreCase("full")) { mc.setExpression(Expression.FULL); } else if (expression.equalsIgnoreCase("sample")) { mc.setExpression(Expression.SAMPLE); } else if (expression.equalsIgnoreCase("nonstop")) { mc.setExpression(Expression.NONSTOP); } } try { if (content.getAttributeValue("fileSize") != null) { mc.setFileSize(Long.valueOf(content.getAttributeValue("fileSize"))); } } catch (final Exception ex) { LOG.warn("Exception parsing content tag.", ex); } try { if (content.getAttributeValue("framerate") != null) { mc.setFramerate(Float.valueOf(content.getAttributeValue("framerate"))); } } catch (final Exception ex) { LOG.warn("Exception parsing content tag.", ex); } try { if (content.getAttributeValue("height") != null) { mc.setHeight(Integer.valueOf(content.getAttributeValue("height"))); } } catch (final Exception ex) { LOG.warn("Exception parsing content tag.", ex); } mc.setLanguage(content.getAttributeValue("lang")); mc.setMetadata(parseMetadata(content)); try { if (content.getAttributeValue("samplingrate") != null) { mc.setSamplingrate(Float.valueOf(content.getAttributeValue("samplingrate"))); } } catch (final Exception ex) { LOG.warn("Exception parsing content tag.", ex); } mc.setType(content.getAttributeValue("type")); try { if (content.getAttributeValue("width") != null) { mc.setWidth(Integer.valueOf(content.getAttributeValue("width"))); } } catch (final Exception ex) { LOG.warn("Exception parsing content tag.", ex); } if (content.getAttributeValue("isDefault") != null) { mc.setDefaultContent(Boolean.valueOf(content.getAttributeValue("isDefault"))); } } else { LOG.warn("Could not find MediaContent."); } } } catch (final Exception ex) { LOG.warn("Exception parsing content tag.", ex); } return values.toArray(new MediaContent[values.size()]); }
From source file:com.rometools.modules.mediarss.io.MediaModuleParser.java
License:Open Source License
private Metadata parseMetadata(final Element e) { final Metadata md = new Metadata(); // categories {/*from w ww. j a va2s . co m*/ final List<Element> categories = e.getChildren("category", getNS()); final ArrayList<Category> values = new ArrayList<Category>(); for (int i = 0; categories != null && i < categories.size(); i++) { try { final Element cat = categories.get(i); values.add(new Category(cat.getAttributeValue("scheme"), cat.getAttributeValue("label"), cat.getText())); } catch (final Exception ex) { LOG.warn("Exception parsing category tag.", ex); } } md.setCategories(values.toArray(new Category[values.size()])); } // copyright try { final Element copy = e.getChild("copyright", getNS()); if (copy != null) { md.setCopyright(copy.getText()); md.setCopyrightUrl( copy.getAttributeValue("url") != null ? new URI(copy.getAttributeValue("url")) : null); } } catch (final Exception ex) { LOG.warn("Exception parsing copyright tag.", ex); } // credits { final List<Element> credits = e.getChildren("credit", getNS()); final ArrayList<Credit> values = new ArrayList<Credit>(); for (int i = 0; credits != null && i < credits.size(); i++) { try { final Element cred = credits.get(i); values.add(new Credit(cred.getAttributeValue("scheme"), cred.getAttributeValue("role"), cred.getText())); md.setCredits(values.toArray(new Credit[values.size()])); } catch (final Exception ex) { LOG.warn("Exception parsing credit tag.", ex); } } } // description try { final Element description = e.getChild("description", getNS()); if (description != null) { md.setDescription(description.getText()); md.setDescriptionType(description.getAttributeValue("type")); } } catch (final Exception ex) { LOG.warn("Exception parsing description tag.", ex); } // hash try { final Element hash = e.getChild("hash", getNS()); if (hash != null) { md.setHash(new Hash(hash.getAttributeValue("algo"), hash.getText())); } } catch (final Exception ex) { LOG.warn("Exception parsing hash tag.", ex); } // keywords { final Element keywords = e.getChild("keywords", getNS()); if (keywords != null) { final StringTokenizer tok = new StringTokenizer(keywords.getText(), ","); final String[] value = new String[tok.countTokens()]; for (int i = 0; tok.hasMoreTokens(); i++) { value[i] = tok.nextToken().trim(); } md.setKeywords(value); } } // ratings { final ArrayList<Rating> values = new ArrayList<Rating>(); final List<Element> ratings = e.getChildren("rating", getNS()); for (final Element ratingElement : ratings) { try { final String ratingText = ratingElement.getText(); String ratingScheme = Strings.trimToNull(ratingElement.getAttributeValue("scheme")); if (ratingScheme == null) { ratingScheme = "urn:simple"; } final Rating rating = new Rating(ratingScheme, ratingText); values.add(rating); } catch (final Exception ex) { LOG.warn("Exception parsing rating tag.", ex); } } md.setRatings(values.toArray(new Rating[values.size()])); } // text { final List<Element> texts = e.getChildren("text", getNS()); final ArrayList<Text> values = new ArrayList<Text>(); for (int i = 0; texts != null && i < texts.size(); i++) { try { final Element text = texts.get(i); final Time start = text.getAttributeValue("start") == null ? null : new Time(text.getAttributeValue("start")); final Time end = text.getAttributeValue("end") == null ? null : new Time(text.getAttributeValue("end")); values.add(new Text(text.getAttributeValue("type"), text.getTextTrim(), start, end)); } catch (final Exception ex) { LOG.warn("Exception parsing text tag.", ex); } } md.setText(values.toArray(new Text[values.size()])); } // thumbnails { final ArrayList<Thumbnail> values = new ArrayList<Thumbnail>(); final List<Element> thumbnails = e.getChildren("thumbnail", getNS()); for (final Element thumb : thumbnails) { try { final String timeAttr = Strings.trimToNull(thumb.getAttributeValue("time")); Time time = null; if (timeAttr != null) { time = new Time(timeAttr); } final String widthAttr = thumb.getAttributeValue("width"); final Integer width = Integers.parse(widthAttr); final String heightAttr = thumb.getAttributeValue("height"); final Integer height = Integers.parse(heightAttr); final String url = thumb.getAttributeValue("url"); final URI uri = new URI(url); final Thumbnail thumbnail = new Thumbnail(uri, width, height, time); values.add(thumbnail); } catch (final Exception ex) { LOG.warn("Exception parsing thumbnail tag.", ex); } } md.setThumbnail(values.toArray(new Thumbnail[values.size()])); } // title { final Element title = e.getChild("title", getNS()); if (title != null) { md.setTitle(title.getText()); md.setTitleType(title.getAttributeValue("type")); } } // restrictions { final List<Element> restrictions = e.getChildren("restriction", getNS()); final ArrayList<Restriction> values = new ArrayList<Restriction>(); for (int i = 0; i < restrictions.size(); i++) { final Element r = 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; } final Restriction value = new Restriction(relationship, type, r.getTextTrim()); values.add(value); } md.setRestrictions(values.toArray(new Restriction[values.size()])); } // handle adult { final Element adult = e.getChild("adult", getNS()); if (adult != null && md.getRatings().length == 0) { final 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); } } return md; }