List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:org.lnicholls.galleon.togo.ToGo.java
License:Open Source License
public void getvideoDetails(HttpClient client, Video video, String url) { GetMethod get = null;/*from w w w. j a v a2 s . c o m*/ try { // System.out.println(httpget.getResponseBodyAsString()); get = new GetMethod(url); client.executeMethod(get); SAXReader saxReader = new SAXReader(); Document document = saxReader.read(get.getResponseBodyAsStream()); // Get the root element Element root = document.getRootElement(); // <TiVoContainer> Element showing = root.element("showing"); if (showing != null) { Element element = showing; if (element != null) { Element node = element.element("partCount"); if (node != null) try { video.setPartCount(new Integer(node.getText())); } catch (Exception ex) { log.error("Could not set part count", ex); } node = element.element("partIndex"); if (node != null) try { video.setPartIndex(new Integer(node.getText())); } catch (Exception ex) { log.error("Could not set part index", ex); } Element program = element.element("program"); if (program != null) { node = program.element("vActor"); if (node != null) video.setActors(getElements(node)); node = program.element("vAdvisory"); if (node != null) video.setAdvisories(getElements(node)); node = program.element("vChoreographer"); if (node != null) video.setChoreographers(getElements(node)); node = program.element("vChoreographer"); if (node != null) video.setChoreographers(getElements(node)); node = program.element("colorCode"); if (node != null) { video.setColor(node.getText()); try { video.setColorCode(Integer.parseInt(node.attribute("value").getText())); } catch (Exception ex) { log.error("Could not set color code", ex); } } node = program.element("description"); if (node != null) video.setDescription(node.getTextTrim()); node = program.element("vDirector"); if (node != null) video.setDirectors(getElements(node)); node = program.element("episodeNumber"); if (node != null) try { video.setEpisodeNumber(Integer.parseInt(node.getTextTrim())); } catch (Exception ex) { log.error("Could not episode number", ex); } node = program.element("episodeTitle"); if (node != null) video.setEpisodeTitle(node.getTextTrim()); node = program.element("vExecProducer"); if (node != null) video.setExecProducers(getElements(node)); node = program.element("vProgramGenre"); if (node != null) video.setProgramGenre(getElements(node)); node = program.element("vGuestStar"); if (node != null) video.setGuestStars(getElements(node)); node = program.element("vHost"); if (node != null) video.setHosts(getElements(node)); node = program.element("isEpisode"); if (node != null) video.setEpisodic(Boolean.valueOf(node.getTextTrim())); node = program.element("originalAirDate"); if (node != null) { ParsePosition pos = new ParsePosition(0); Date date = mTimeDateFormat.parse(node.getTextTrim(), pos); if (date == null) date = new Date(0); video.setOriginalAirDate(date); // 2000-03-25T00:00:00Z } node = program.element("vProducer"); if (node != null) video.setProducers(getElements(node)); Element series = program.element("series"); if (series != null) { node = series.element("vSeriesGenre"); if (node != null) video.setSeriesGenre(getElements(node)); node = series.element("seriesTitle"); if (node != null) video.setSeriesTitle(node.getTextTrim()); } node = program.element("showType"); if (node != null) { video.setShowType(node.getTextTrim()); try { video.setShowTypeValue(new Integer(node.attribute("value").getText())); } catch (Exception ex) { log.error("Could not set showtype value", ex); } } node = program.element("title"); if (node != null) video.setTitle(node.getTextTrim()); node = program.element("vWriter"); if (node != null) video.setWriters(getElements(node)); } Element channel = element.element("channel"); if (channel != null) { node = channel.element("displayMajorNumber"); if (node != null) try { video.setChannelMajorNumber(Integer.parseInt(node.getTextTrim())); } catch (Exception ex) { log.error("Could not set channel major number", ex); } node = channel.element("displayMinorNumber"); if (node != null) try { video.setChannelMinorNumber(Integer.parseInt(node.getTextTrim())); } catch (Exception ex) { log.error("Could not set channel minor number", ex); } node = channel.element("callsign"); if (node != null) video.setCallsign(node.getTextTrim()); } Element rating = element.element("tvRating"); if (rating != null) { video.setRating(rating.getTextTrim()); try { video.setRatingValue(new Integer(rating.attribute("value").getText())); } catch (Exception ex) { log.error("Could not set rating value", ex); } } } } showing = root.element("vActualShowing"); if (showing != null) { Iterator iterator = showing.elementIterator("element"); while (iterator.hasNext()) { Element element = (Element) iterator.next(); Element node = null; Element channel = element.element("channel"); if (channel != null) { node = channel.element("displayMajorNumber"); if (node != null) try { int value = Integer.parseInt(node.getTextTrim()); if (value != video.getChannelMajorNumber()) break; video.setChannelMajorNumber(value); } catch (Exception ex) { log.error("Could not set channel major number", ex); } node = channel.element("displayMinorNumber"); if (node != null) try { int value = Integer.parseInt(node.getTextTrim()); if (value != video.getChannelMinorNumber()) break; video.setChannelMinorNumber(value); } catch (Exception ex) { log.error("Could not set channel minor number", ex); } node = channel.element("callsign"); if (node != null && video.getCallsign() == null) video.setCallsign(node.getTextTrim()); } node = element.element("partCount"); if (node != null && video.getPartCount() == null) try { video.setPartCount(new Integer(node.getText())); } catch (Exception ex) { log.error("Could not set part count", ex); } node = element.element("partIndex"); if (node != null && video.getPartIndex() == null) try { video.setPartIndex(new Integer(node.getText())); } catch (Exception ex) { log.error("Could not set part index", ex); } Element program = element.element("program"); if (program != null) { node = program.element("vActor"); if (node != null && video.getActors() == null) video.setActors(getElements(node)); node = program.element("vAdvisory"); if (node != null && video.getAdvisories() == null) video.setAdvisories(getElements(node)); node = program.element("vChoreographer"); if (node != null && video.getChoreographers() == null) video.setChoreographers(getElements(node)); node = program.element("vChoreographer"); if (node != null && video.getChoreographers() == null) video.setChoreographers(getElements(node)); node = program.element("colorCode"); if (node != null && video.getColor() == null) { video.setColor(node.getText()); try { video.setColorCode(Integer.parseInt(node.attribute("value").getText())); } catch (Exception ex) { log.error("Could not set color code", ex); } } node = program.element("description"); if (node != null && video.getDescription() == null) video.setDescription(node.getTextTrim()); node = program.element("vDirector"); if (node != null && video.getDirectors() == null) video.setDirectors(getElements(node)); node = program.element("episodeNumber"); if (node != null && video.getEpisodeNumber() != 0) try { video.setEpisodeNumber(Integer.parseInt(node.getTextTrim())); } catch (Exception ex) { log.error("Could not episode number", ex); } node = program.element("episodeTitle"); if (node != null && video.getEpisodeTitle() == null) video.setEpisodeTitle(node.getTextTrim()); node = program.element("vExecProducer"); if (node != null && video.getExecProducers() == null) video.setExecProducers(getElements(node)); node = program.element("vProgramGenre"); if (node != null && video.getProgramGenre() == null) video.setProgramGenre(getElements(node)); node = program.element("vGuestStar"); if (node != null && video.getGuestStars() == null) video.setGuestStars(getElements(node)); node = program.element("vHost"); if (node != null && video.getHosts() == null) video.setHosts(getElements(node)); node = program.element("isEpisode"); if (node != null && video.getEpisodic() == null) video.setEpisodic(Boolean.valueOf(node.getTextTrim())); node = program.element("originalAirDate"); if (node != null && video.getOriginalAirDate() == null) { ParsePosition pos = new ParsePosition(0); Date date = mTimeDateFormat.parse(node.getTextTrim(), pos); if (date == null) date = new Date(0); video.setOriginalAirDate(date); // 2000-03-25T00:00:00Z } node = program.element("vProducer"); if (node != null && video.getProducers() == null) video.setProducers(getElements(node)); Element series = program.element("series"); if (series != null && video.getSeriesGenre() == null) { node = series.element("vSeriesGenre"); if (node != null) video.setSeriesGenre(getElements(node)); node = series.element("seriesTitle"); if (node != null) video.setSeriesTitle(node.getTextTrim()); } node = program.element("showType"); if (node != null && video.getShowType() == null) { video.setShowType(node.getTextTrim()); try { video.setShowTypeValue(new Integer(node.attribute("value").getText())); } catch (Exception ex) { log.error("Could not set showtype value", ex); } } node = program.element("title"); if (node != null && video.getTitle() == null) video.setTitle(node.getTextTrim()); node = program.element("vWriter"); if (node != null && video.getWriters() == null) video.setWriters(getElements(node)); } Element rating = element.element("tvRating"); if (rating != null && video.getRating() == null) { video.setRating(rating.getTextTrim()); try { video.setRatingValue(new Integer(rating.attribute("value").getText())); } catch (Exception ex) { log.error("Could not set rating value", ex); } } } } Element node = root.element("vBookmark"); if (node != null) { /* * <vBookmark> <element> <time>PT4M42.137000000S </time> * </element> </vBookmark> * */ StringBuffer buffer = new StringBuffer(); int counter = 0; for (Iterator iterator = node.elementIterator("element"); iterator.hasNext();) { Element bookmarkElement = (Element) iterator.next(); if (counter++ > 0) buffer.append(";"); buffer.append(Tools.getAttribute(bookmarkElement, "time")); } video.setBookmarks(buffer.toString()); } Element quality = root.element("recordingQuality"); if (quality != null) { video.setRecordingQuality(quality.getTextTrim()); try { video.setRecordingQualityValue(new Integer(quality.attribute("value").getText())); } catch (Exception ex) { log.error("Could not set rating value", ex); } } Element time = root.element("startTime"); if (time != null) { ParsePosition pos = new ParsePosition(0); Date date = mTimeDateFormat.parse(time.getTextTrim(), pos); if (date == null) date = new Date(0); video.setStartTime(date); // 2005-02-23T11:59:58Z } time = root.element("stopTime"); if (time != null) { ParsePosition pos = new ParsePosition(0); Date date = mTimeDateFormat.parse(time.getTextTrim(), pos); if (date == null) date = new Date(0); video.setStopTime(date); // 2005-02-23T11:59:58Z } time = root.element("expirationTime"); if (time != null) { ParsePosition pos = new ParsePosition(0); Date date = mTimeDateFormat.parse(time.getTextTrim(), pos); if (date == null) date = new Date(0); video.setExpirationTime(date); // 2005-02-23T11:59:58Z } } catch (Exception ex) { Tools.logException(ToGo.class, ex); } finally { if (get != null) { get.releaseConnection(); get = null; } } }
From source file:org.lnicholls.galleon.togo.ToGo.java
License:Open Source License
private String getElements(Element node) { StringBuffer buffer = new StringBuffer(); int counter = 0; for (Iterator iterator = node.elementIterator("element"); iterator.hasNext();) { Element element = (Element) iterator.next(); if (counter++ > 0) buffer.append(";"); buffer.append(element.getTextTrim()); }/* w ww. jav a 2 s .co m*/ return buffer.toString(); }
From source file:org.lnicholls.galleon.util.Amazon.java
License:Open Source License
public static synchronized Image getImage(String key, URL url) { Image image = null;// www . ja v a 2 s . c o m if (System.currentTimeMillis() - mTime < 1000) { // Not allowed to call AWS more than once a second try { Thread.currentThread().sleep(1000); } catch (Exception ex) { } } try { SAXReader saxReader = new SAXReader(); // http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&SubscriptionId=1S15VY5XR4PV42R2YRG2&Operation=ItemSearch&SearchIndex=Music&ResponseGroup=Images&Artist=" // + artist + "&Title=" + title String page = Tools.getPage(url); if (page != null && page.length() > 0) { log.debug("Amazon images: " + page); StringReader stringReader = new StringReader(page); Document document = saxReader.read(stringReader); //Document document = saxReader.read(new File("d:/galleon/amazon.xml")); Element root = document.getRootElement(); Element items = root.element("Items"); if (items != null) { for (Iterator i = items.elementIterator("Item"); i.hasNext();) { Element item = (Element) i.next(); Element someImage = item.element("LargeImage"); if (someImage == null) someImage = item.element("MediumImage"); if (someImage == null) someImage = item.element("SmallImage"); if (someImage != null) { Element address = someImage.element("URL"); if (address != null) { log.debug(address.getTextTrim()); Element height = someImage.element("Height"); Element width = someImage.element("Width"); try { image = Tools.getImage(new URL(address.getTextTrim()), Integer.parseInt(height.getTextTrim()), Integer.parseInt(width.getTextTrim())); break; } catch (Exception ex) { log.error("Could not download Amazon image: " + address.getTextTrim(), ex); } } } } } } } catch (Exception ex) { Tools.logException(Amazon.class, ex, "Could parse AWS url: " + url.toExternalForm()); } mTime = System.currentTimeMillis(); return image; }
From source file:org.lnicholls.galleon.util.Tools.java
License:Open Source License
public static String getAttribute(Element element, String name) { String value = element.attributeValue(name); if (value == null) { Element child = element.element(name); if (child != null) return child.getTextTrim(); } else// w w w.j a va 2 s .co m value = value.trim(); return value; }
From source file:org.lushlife.guicexml.internal.property.PropertyManagement.java
License:Apache License
@SuppressWarnings("unchecked") public PropertyValue toPropertyValue(Element value) { List list = value.elements(); if (list.size() == 0) { return toPropertyValue(value.getTextTrim()); }//from w w w . j a v a 2 s .c o m Element element = (Element) list.get(0); if (element.getName().equals("value")) { return toListPropertyValue(value); } if (element.getName().equals("key")) { return toMapPropertyValue(value); } // TODO message throw new IllegalArgumentException("" + value.asXML().replace("\r", " ")); }
From source file:org.lushlife.guicexml.internal.property.PropertyManagement.java
License:Apache License
@SuppressWarnings("unchecked") public PropertyValue toPropertyValue(Element element, String attribute) { PropertyValue value;/* w w w .j a v a2 s. c om*/ List list = element.elements(); if (list.size() == 0) { String attr = element.attributeValue(attribute); if (attr != null) { value = toPropertyValue(attr); } else { value = toPropertyValue(element.getTextTrim()); } } else { value = toPropertyValue(element); } return value; }
From source file:org.mitre.ace2004.callisto.config.RNGParser.java
License:Open Source License
private Set readAttributeChoices(Element attribute) { // for now only choice and /empty/ allowed Element choice = attribute.element("choice"); if (choice == null && attribute.elements().size() > 0) { parseError(attribute, "Only 'choice' allowed in 'attribute'"); return null; }/*from www . ja v a 2 s. co m*/ Set valueSet = new LinkedHashSet(); if (attribute.elements().size() > 0) { Iterator vals = choice.elements("value").iterator(); while (vals.hasNext()) { Element value = (Element) vals.next(); // datatype checking goes here String constraint = value.getTextTrim(); if (DEBUG > 0) System.err.println(" Value: " + constraint); valueSet.add(constraint); } } return valueSet; }
From source file:org.mskcc.cbio.portal.scripts.ImportCaisesClinicalXML.java
License:Open Source License
private static void addAllDataUnderNode(ClinicalEvent clinicalEvent, Element element) { for (Iterator i = element.elementIterator(); i.hasNext();) { Element child = (Element) i.next(); clinicalEvent.addEventDatum(child.getName(), child.getTextTrim()); }/*from w ww.j a v a 2 s.c o m*/ }
From source file:org.neuclear.asset.contracts.Asset.java
License:Open Source License
private static double extractMinimumTransactionAmount(Element elem) { Element melem = XMLTools.getByID(elem, "asset.minimum"); if (melem == null || Utility.isEmpty(melem.getTextTrim())) return 0.0; return Double.parseDouble(melem.getTextTrim()); }
From source file:org.neuclear.asset.contracts.Asset.java
License:Open Source License
private static int extractDecimalPoints(Element elem) { Element melem = XMLTools.getByID(elem, "asset.decimalpoints"); if (melem == null || Utility.isEmpty(melem.getTextTrim())) return 0; return Integer.parseInt(melem.getTextTrim()); }