List of usage examples for org.jdom2 Element addContent
@Override public Element addContent(final Collection<? extends Content> newContent)
From source file:com.rometools.modules.photocast.io.Generator.java
License:Open Source License
@Override public void generate(final Module module, final Element element) { if (!(module instanceof PhotocastModule)) { return;/* ww w .j av a 2s . com*/ } final PhotocastModule pm = (PhotocastModule) module; if (element.getName().equals("channel") || element.getName().equals("feed")) { element.addContent(generateSimpleElement("feedVersion", FEED_VERSION)); return; } element.addContent(generateSimpleElement("photoDate", Parser.PHOTO_DATE_FORMAT.format(pm.getPhotoDate()))); element.addContent(generateSimpleElement("cropDate", Parser.CROP_DATE_FORMAT.format(pm.getCropDate()))); element.addContent(generateSimpleElement("thumbnail", pm.getThumbnailUrl().toString())); element.addContent(generateSimpleElement("image", pm.getImageUrl().toString())); final Element e = new Element("metadata", NS); final Element pd = new Element("PhotoDate", ""); pd.addContent(pm.getMetadata().getPhotoDate().toString()); e.addContent(pd); final Element com = new Element("Comments", ""); com.addContent(pm.getMetadata().getComments()); e.addContent(com); element.addContent(e); }
From source file:com.rometools.modules.slash.io.SlashModuleGenerator.java
License:Open Source License
@Override public void generate(final Module module, final Element element) { if (!(module instanceof Slash)) { return;/* w w w .ja v a 2s . co m*/ } final Slash slash = (Slash) module; if (slash.getComments() != null) { element.addContent(generateSimpleElement("comments", slash.getComments().toString())); } if (slash.getDepartment() != null) { element.addContent(generateSimpleElement("department", slash.getDepartment())); } if (slash.getSection() != null) { element.addContent(generateSimpleElement("section", slash.getSection())); } if (slash.getHitParade() != null && slash.getHitParade().length > 0) { final StringBuffer buff = new StringBuffer(); final Integer[] p = slash.getHitParade(); for (int i = 0; i < p.length; i++) { if (i != 0) { buff.append(","); } buff.append(p[i]); } element.addContent(generateSimpleElement("hit_parade", buff.toString())); } }
From source file:com.rometools.modules.slash.io.SlashModuleGenerator.java
License:Open Source License
protected Element generateSimpleElement(final String name, final String value) { final Element element = new Element(name, SlashModuleGenerator.NAMESPACE); element.addContent(value); return element; }
From source file:com.rometools.modules.sle.io.ModuleParser.java
License:Apache License
public void insertValues(final SimpleListExtension sle, final List<Element> elements) { for (int i = 0; elements != null && i < elements.size(); i++) { final Element e = elements.get(i); final Group[] groups = sle.getGroupFields(); for (final Group group2 : groups) { final Element value = e.getChild(group2.getElement(), group2.getNamespace()); if (value == null) { continue; }//from ww w.j a v a2 s. c o m final Element group = new Element("group", TEMP); addNotNullAttribute(group, "element", group2.getElement()); addNotNullAttribute(group, "label", group2.getLabel()); addNotNullAttribute(group, "value", value.getText()); addNotNullAttribute(group, "ns", group2.getNamespace().getURI()); e.addContent(group); } final Sort[] sorts = sle.getSortFields(); for (final Sort sort2 : sorts) { LOG.debug("Inserting for {} {}", sort2.getElement(), sort2.getDataType()); final Element sort = new Element("sort", TEMP); // this is the default sort order, so I am just going to ignore // the actual values and add a number type. It really shouldn't // work this way. I should be checking to see if any of the elements // defined have a value then use that value. This will preserve the // sort order, however, if anyone is using the SleEntry to display // the value of the field, it will not give the correct value. // This, however, would require knowledge in the item parser that I don't // have right now. if (sort2.getDefaultOrder()) { sort.setAttribute("label", sort2.getLabel()); sort.setAttribute("value", Integer.toString(i)); sort.setAttribute("data-type", Sort.NUMBER_TYPE); e.addContent(sort); continue; } // LOG.debug(e.getName()); final Element value = e.getChild(sort2.getElement(), sort2.getNamespace()); if (value == null) { LOG.debug("No value for {} : {}", sort2.getElement(), sort2.getNamespace()); } else { LOG.debug("{} value: {}", sort2.getElement(), value.getText()); } if (value == null) { continue; } addNotNullAttribute(sort, "label", sort2.getLabel()); addNotNullAttribute(sort, "element", sort2.getElement()); addNotNullAttribute(sort, "value", value.getText()); addNotNullAttribute(sort, "data-type", sort2.getDataType()); addNotNullAttribute(sort, "ns", sort2.getNamespace().getURI()); e.addContent(sort); LOG.debug("Added {} {} = {}", sort, sort2.getLabel(), value.getText()); } } }
From source file:com.rometools.modules.thr.io.ThreadingModuleGenerator.java
License:Apache License
@Override public void generate(Module module, Element element) { if (module != null && module instanceof ThreadingModule) { ThreadingModule threadedModule = (ThreadingModule) module; Element inReplyTo = new Element("in-reply-to", NAMESPACE); if (threadedModule.getHref() != null) { inReplyTo.setAttribute("href", threadedModule.getHref()); }//from w w w . j av a2 s . c o m if (threadedModule.getRef() != null) { inReplyTo.setAttribute("ref", threadedModule.getRef()); } if (threadedModule.getType() != null) { inReplyTo.setAttribute("type", threadedModule.getType()); } if (threadedModule.getSource() != null) { inReplyTo.setAttribute("source", threadedModule.getSource()); } element.addContent(inReplyTo); } }
From source file:com.rometools.modules.yahooweather.io.WeatherModuleGenerator.java
License:Open Source License
@Override public void generate(final Module module, final Element element) { if (!(module instanceof YWeatherModuleImpl)) { return;//from w w w . j a v a 2 s.com } final YWeatherModuleImpl weather = (YWeatherModuleImpl) module; if (weather.getAstronomy() != null) { final Element astro = new Element("astronomy", WeatherModuleGenerator.NS); if (weather.getAstronomy().getSunrise() != null) { astro.setAttribute("sunrise", TIME_ONLY.format(weather.getAstronomy().getSunrise()).toLowerCase()); } if (weather.getAstronomy().getSunrise() != null) { astro.setAttribute("sunset", TIME_ONLY.format(weather.getAstronomy().getSunset()).toLowerCase()); } element.addContent(astro); } if (weather.getAtmosphere() != null) { final Element atmos = new Element("atmosphere", WeatherModuleGenerator.NS); atmos.setAttribute("humidity", Integer.toString(weather.getAtmosphere().getHumidity())); atmos.setAttribute("visibility", Integer.toString((int) (weather.getAtmosphere().getVisibility() * 100d))); atmos.setAttribute("pressure", Double.toString(weather.getAtmosphere().getPressure())); if (weather.getAtmosphere().getChange() != null) { atmos.setAttribute("rising", Integer.toString(weather.getAtmosphere().getChange().getCode())); } element.addContent(atmos); } if (weather.getCondition() != null) { final Element condition = new Element("condition", WeatherModuleGenerator.NS); if (weather.getCondition().getText() != null) { condition.setAttribute("text", weather.getCondition().getText()); } if (weather.getCondition().getCode() != null) { condition.setAttribute("code", Integer.toString(weather.getCondition().getCode().getCode())); } if (weather.getCondition().getDate() != null) { condition.setAttribute("date", LONG_DATE.format(weather.getCondition().getDate()) .replaceAll("AM", "am").replaceAll("PM", "pm")); } condition.setAttribute("temp", Integer.toString(weather.getCondition().getTemperature())); element.addContent(condition); } if (weather.getLocation() != null) { final Element location = new Element("location", WeatherModuleGenerator.NS); if (weather.getLocation().getCity() != null) { location.setAttribute("city", weather.getLocation().getCity()); } if (weather.getLocation().getRegion() != null) { location.setAttribute("region", weather.getLocation().getRegion()); } if (weather.getLocation().getCountry() != null) { location.setAttribute("country", weather.getLocation().getCountry()); } element.addContent(location); } if (weather.getUnits() != null) { final Element units = new Element("units", WeatherModuleGenerator.NS); if (weather.getUnits().getDistance() != null) { units.setAttribute("distance", weather.getUnits().getDistance()); } if (weather.getUnits().getPressure() != null) { units.setAttribute("pressure", weather.getUnits().getPressure()); } if (weather.getUnits().getSpeed() != null) { units.setAttribute("speed", weather.getUnits().getSpeed()); } if (weather.getUnits().getTemperature() != null) { units.setAttribute("temperature", weather.getUnits().getTemperature()); } element.addContent(units); } if (weather.getWind() != null) { final Element wind = new Element("wind", WeatherModuleGenerator.NS); wind.setAttribute("chill", Integer.toString(weather.getWind().getChill())); wind.setAttribute("direction", Integer.toString(weather.getWind().getDirection())); wind.setAttribute("speed", Integer.toString(weather.getWind().getSpeed())); element.addContent(wind); } if (weather.getForecasts() != null) { for (int i = 0; i < weather.getForecasts().length; i++) { final Element forecast = new Element("forecast", WeatherModuleGenerator.NS); final Forecast f = weather.getForecasts()[i]; if (f.getCode() != null) { forecast.setAttribute("code", Integer.toString(f.getCode().getCode())); } if (f.getDate() != null) { forecast.setAttribute("date", SHORT_DATE.format(f.getDate())); } if (f.getDay() != null) { forecast.setAttribute("day", f.getDay()); } if (f.getText() != null) { forecast.setAttribute("text", f.getText()); } forecast.setAttribute("high", Integer.toString(f.getHigh())); forecast.setAttribute("low", Integer.toString(f.getLow())); element.addContent(forecast); } } }
From source file:com.rometools.modules.yahooweather.io.WeatherModuleGenerator.java
License:Open Source License
protected Element generateSimpleElement(final String name, final String value) { final Element element = new Element(name, WeatherModuleGenerator.NS); element.addContent(value); return element; }
From source file:com.rometools.opml.io.impl.OPML10Generator.java
License:Apache License
/** * Creates an XML document (JDOM) for the given feed bean. * * @param feed the feed bean to generate the XML document from. * @return the generated XML document (JDOM). * @throws IllegalArgumentException thrown if the type of the given feed bean does not match with the type of the * WireFeedGenerator./*from w ww. ja va2 s . c om*/ * @throws FeedException thrown if the XML Document could not be created. */ @Override public Document generate(final WireFeed feed) throws IllegalArgumentException, FeedException { if (!(feed instanceof Opml)) { throw new IllegalArgumentException("Not an OPML file"); } final Opml opml = (Opml) feed; final Document doc = new Document(); final Element root = new Element("opml"); root.setAttribute("version", "1.0"); doc.addContent(root); final Element head = generateHead(opml); if (head != null) { root.addContent(head); } final Element body = new Element("body"); root.addContent(body); super.generateFeedModules(opml.getModules(), root); body.addContent(generateOutlines(opml.getOutlines())); return doc; }
From source file:com.rometools.opml.io.impl.OPML10Generator.java
License:Apache License
protected boolean addNotNullSimpleElement(final Element target, final String name, final Object value) { if (target == null || name == null || value == null) { return false; }// w w w . j a v a 2 s . c o m final Element e = new Element(name); e.addContent(value.toString()); target.addContent(e); return true; }
From source file:com.rometools.opml.io.impl.OPML10Generator.java
License:Apache License
protected Element generateOutline(final Outline outline) { final Element e = new Element("outline"); addNotNullAttribute(e, "text", outline.getText()); addNotNullAttribute(e, "type", outline.getType()); addNotNullAttribute(e, "title", outline.getTitle()); if (outline.isBreakpoint()) { addNotNullAttribute(e, "isBreakpoint", "true"); }//from www .java2 s . co m if (outline.isComment()) { addNotNullAttribute(e, "isComment", "true"); } final List<Attribute> atts = Collections.synchronizedList(outline.getAttributes()); for (int i = 0; i < atts.size(); i++) { final Attribute att = atts.get(i); addNotNullAttribute(e, att.getName(), att.getValue()); } super.generateItemModules(outline.getModules(), e); e.addContent(generateOutlines(outline.getChildren())); return e; }