List of usage examples for org.jdom2 Element getTextTrim
public String getTextTrim()
From source file:com.rhythm.louie.server.TaskSchedulerProperties.java
License:Apache License
public static void processProperties(Element scheduler) { for (Element child : scheduler.getChildren()) { String elemName = child.getName().toLowerCase(); String elemValue = child.getTextTrim(); switch (elemName) { case POOL_SIZE: threadPoolSize = Integer.parseInt(elemValue); break; case JNDI: jndiKey = elemValue;// w w w. j a v a 2s .c o m break; default: LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected scheduler property {}:{}", elemName, elemValue); break; } } }
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 ww w. j a v a2 s .c o 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.cc.io.ModuleParserRSS2.java
License:Open Source License
@Override public Module parse(final Element element, final Locale locale) { final CreativeCommonsImpl module = new CreativeCommonsImpl(); // Do channel global {// www .j a v a 2 s . c o m Element root = element; while (!root.getName().equals("channel") && !root.getName().equals("feed")) { root = root.getParentElement(); } final ArrayList<License> licenses = new ArrayList<License>(); List<Element> items = null; if (root.getName().equals("channel")) { items = root.getChildren("item"); } else { items = root.getChildren("entry"); } final Iterator<Element> iit = items.iterator(); while (iit.hasNext()) { final Element item = iit.next(); final List<Element> licenseTags = item.getChildren("license", NS); final Iterator<Element> lit = licenseTags.iterator(); while (lit.hasNext()) { final Element licenseTag = lit.next(); final License license = License.findByValue(licenseTag.getTextTrim()); if (!licenses.contains(license)) { ; } licenses.add(license); } } if (!licenses.isEmpty()) { module.setAllLicenses(licenses.toArray(new License[0])); } } // do element local final ArrayList<License> licenses = new ArrayList<License>(); final List<Element> licenseTags = element.getChildren("license", NS); final Iterator<Element> it = licenseTags.iterator(); while (it.hasNext()) { final Element licenseTag = it.next(); licenses.add(License.findByValue(licenseTag.getTextTrim())); } if (!licenses.isEmpty()) { module.setLicenses(licenses.toArray(new License[0])); } if (module.getLicenses() != null && module.getAllLicenses() != null) { return module; } else { return null; } }
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;/*from w w w . jav a2s . 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 Metadata parseMetadata(final Element e) { final Metadata md = new Metadata(); // categories {/*from ww w . j a v a 2s.c om*/ 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; }
From source file:com.rometools.propono.atom.client.ClientCollection.java
License:Open Source License
@Override protected void parseCollectionElement(final Element element) throws ProponoException { if (workspace == null) { return;/*from ww w. ja v a 2 s . c o m*/ } setHref(element.getAttribute("href").getValue()); final Element titleElem = element.getChild("title", AtomService.ATOM_FORMAT); if (titleElem != null) { setTitle(titleElem.getText()); if (titleElem.getAttribute("type", AtomService.ATOM_FORMAT) != null) { setTitleType(titleElem.getAttribute("type", AtomService.ATOM_FORMAT).getValue()); } } final List<Element> acceptElems = element.getChildren("accept", AtomService.ATOM_PROTOCOL); if (acceptElems != null && !acceptElems.isEmpty()) { for (final Element acceptElem : acceptElems) { addAccept(acceptElem.getTextTrim()); } } // Loop to parse <app:categories> element to Categories objects final List<Element> catsElems = element.getChildren("categories", AtomService.ATOM_PROTOCOL); for (final Element catsElem : catsElems) { final Categories cats = new ClientCategories(catsElem, this); addCategories(cats); } }
From source file:com.rometools.propono.atom.common.Collection.java
License:Apache License
protected void parseCollectionElement(final Element element) throws ProponoException { setHref(element.getAttribute("href").getValue()); final Element titleElem = element.getChild("title", AtomService.ATOM_FORMAT); if (titleElem != null) { setTitle(titleElem.getText());/*ww w . j av a 2 s . c o m*/ if (titleElem.getAttribute("type", AtomService.ATOM_FORMAT) != null) { setTitleType(titleElem.getAttribute("type", AtomService.ATOM_FORMAT).getValue()); } } final List<Element> acceptElems = element.getChildren("accept", AtomService.ATOM_PROTOCOL); if (acceptElems != null && !acceptElems.isEmpty()) { for (final Element acceptElem : acceptElems) { addAccept(acceptElem.getTextTrim()); } } // Loop to parse <app:categories> element to Categories objects final List<Element> catsElems = element.getChildren("categories", AtomService.ATOM_PROTOCOL); for (final Element catsElem : catsElems) { final Categories cats = new Categories(catsElem, baseURI); addCategories(cats); } }
From source file:com.rometools.propono.atom.common.rome.AppModuleParser.java
License:Apache License
/** Parse JDOM element into module */ @Override/*from w w w. j a v a 2s. c om*/ public Module parse(final Element elem, final Locale locale) { final AppModule m = new AppModuleImpl(); final Element control = elem.getChild("control", getContentNamespace()); if (control != null) { final Element draftElem = control.getChild("draft", getContentNamespace()); if (draftElem != null) { if ("yes".equals(draftElem.getText())) { m.setDraft(Boolean.TRUE); } if ("no".equals(draftElem.getText())) { m.setDraft(Boolean.FALSE); } } } final Element edited = elem.getChild("edited", getContentNamespace()); if (edited != null) { try { m.setEdited(DateParser.parseW3CDateTime(edited.getTextTrim(), locale)); } catch (final Exception ignored) { } } return m; }
From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.AbstractModule.java
License:Apache License
protected boolean isOperator(final Element element, final String operator) { return isOperator(element) && element.getTextTrim().equals(operator); }
From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.OperatorNormalizer.java
License:Apache License
private boolean isSpareOperator(final Element operator, final Collection<String> spareOperators) { assert operator != null && spareOperators != null && isOperator(operator); return (isEnabled(REMOVE_EMPTY_OPERATORS) && operator.getText().isEmpty()) || (spareOperators.contains(operator.getTextTrim())); }