List of usage examples for org.jdom2 Element addContent
@Override public Element addContent(final Collection<? extends Content> newContent)
From source file:com.rometools.modules.cc.io.CCModuleGenerator.java
License:Open Source License
private void generateRSS2(final CreativeCommons module, final Element element) { final License[] licenses = module.getLicenses(); for (int i = 0; licenses != null && i < licenses.length; i++) { final Element license = new Element("license", RSS2); license.setText(licenses[i].getValue()); element.addContent(license); }//from w ww. j a v a 2 s. co m }
From source file:com.rometools.modules.content.io.ContentModuleGenerator.java
License:Open Source License
@Override public void generate(final com.rometools.rome.feed.module.Module module, final org.jdom2.Element element) { // this is not necessary, it is done to avoid the namespace definition in every item. Element root = element;/*from www . j a v a 2 s. c om*/ while (root.getParent() != null && root.getParent() instanceof Element) { root = (Element) root.getParent(); } root.addNamespaceDeclaration(CONTENT_NS); if (!(module instanceof ContentModule)) { return; } final ContentModule cm = (ContentModule) module; final List<String> encodeds = cm.getEncodeds(); if (encodeds != null) { LOG.debug("{}", cm.getEncodeds().size()); for (int i = 0; i < encodeds.size(); i++) { element.addContent(generateCDATAElement("encoded", encodeds.get(i).toString())); } } final List<ContentItem> contentItems = cm.getContentItems(); if (contentItems != null && !contentItems.isEmpty()) { final Element items = new Element("items", CONTENT_NS); final Element bag = new Element("Bag", RDF_NS); items.addContent(bag); for (int i = 0; i < contentItems.size(); i++) { final ContentItem contentItem = contentItems.get(i); final Element li = new Element("li", RDF_NS); final Element item = new Element("item", CONTENT_NS); if (contentItem.getContentAbout() != null) { final Attribute about = new Attribute("about", contentItem.getContentAbout(), RDF_NS); item.setAttribute(about); } if (contentItem.getContentFormat() != null) { // LOG.debug( "Format"); final Element format = new Element("format", CONTENT_NS); final Attribute formatResource = new Attribute("resource", contentItem.getContentFormat(), RDF_NS); format.setAttribute(formatResource); item.addContent(format); } if (contentItem.getContentEncoding() != null) { // LOG.debug( "Encoding"); final Element encoding = new Element("encoding", CONTENT_NS); final Attribute encodingResource = new Attribute("resource", contentItem.getContentEncoding(), RDF_NS); encoding.setAttribute(encodingResource); item.addContent(encoding); } if (contentItem.getContentValue() != null) { final Element value = new Element("value", RDF_NS); if (contentItem.getContentValueParseType() != null) { final Attribute parseType = new Attribute("parseType", contentItem.getContentValueParseType(), RDF_NS); value.setAttribute(parseType); } if (contentItem.getContentValueNamespaces() != null) { final List<Namespace> namespaces = contentItem.getContentValueNamespaces(); for (int ni = 0; ni < namespaces.size(); ni++) { value.addNamespaceDeclaration(namespaces.get(ni)); } } final List<Content> detached = new ArrayList<Content>(); for (int c = 0; c < contentItem.getContentValueDOM().size(); c++) { detached.add(contentItem.getContentValueDOM().get(c).clone().detach()); } value.setContent(detached); item.addContent(value); } // end value li.addContent(item); bag.addContent(li); } // end contentItems loop element.addContent(items); } }
From source file:com.rometools.modules.content.io.ContentModuleGenerator.java
License:Open Source License
protected Element generateSimpleElement(final String name, final String value) { final Element element = new Element(name, CONTENT_NS); element.addContent(value); return element; }
From source file:com.rometools.modules.content.io.ContentModuleGenerator.java
License:Open Source License
protected Element generateCDATAElement(final String name, final String value) { final Element element = new Element(name, CONTENT_NS); final CDATA cdata = new CDATA(value); element.addContent(cdata); return element; }
From source file:com.rometools.modules.feedburner.io.FeedBurnerModuleGenerator.java
License:Apache License
@Override public void generate(final Module module, final Element element) { if (!(module instanceof FeedBurner)) { return;/* w w w. j ava 2 s .co m*/ } final FeedBurner feedBurner = (FeedBurner) module; if (feedBurner.getAwareness() != null) { element.addContent(generateSimpleElement("awareness", feedBurner.getAwareness())); } if (feedBurner.getOrigLink() != null) { element.addContent(generateSimpleElement("origLink", feedBurner.getOrigLink())); } if (feedBurner.getOrigEnclosureLink() != null) { element.addContent(generateSimpleElement("origEnclosureLink", feedBurner.getOrigEnclosureLink())); } }
From source file:com.rometools.modules.feedburner.io.FeedBurnerModuleGenerator.java
License:Apache License
protected Element generateSimpleElement(final String name, final String value) { final Element element = new Element(name, FeedBurnerModuleGenerator.NS); element.addContent(value); return element; }
From source file:com.rometools.modules.georss.GMLGenerator.java
License:Apache License
private Element createPosListElement(final PositionList posList) { final Element posElement = new Element("posList", GeoRSSModule.GML_NS); final StringBuffer sb = new StringBuffer(); for (int i = 0; i < posList.size(); ++i) { sb.append(posList.getLatitude(i)).append(" ").append(posList.getLongitude(i)).append(" "); }//from w w w.j a va 2s.co m posElement.addContent(sb.toString()); return posElement; }
From source file:com.rometools.modules.georss.GMLGenerator.java
License:Apache License
@Override public void generate(final Module module, final Element element) { // this is not necessary, it is done to avoid the namespace definition // in every item. Element root = element;/*from www . j a v a 2 s . co m*/ while (root.getParent() != null && root.getParent() instanceof Element) { root = (Element) element.getParent(); } root.addNamespaceDeclaration(GeoRSSModule.SIMPLE_NS); root.addNamespaceDeclaration(GeoRSSModule.GML_NS); final Element whereElement = new Element("where", GeoRSSModule.SIMPLE_NS); element.addContent(whereElement); final GeoRSSModule geoRSSModule = (GeoRSSModule) module; final AbstractGeometry geometry = geoRSSModule.getGeometry(); if (geometry instanceof Point) { final Position pos = ((Point) geometry).getPosition(); final Element pointElement = new Element("Point", GeoRSSModule.GML_NS); whereElement.addContent(pointElement); final Element posElement = new Element("pos", GeoRSSModule.GML_NS); posElement.addContent(String.valueOf(pos.getLatitude()) + " " + String.valueOf(pos.getLongitude())); pointElement.addContent(posElement); } else if (geometry instanceof LineString) { final PositionList posList = ((LineString) geometry).getPositionList(); final Element lineElement = new Element("LineString", GeoRSSModule.GML_NS); lineElement.addContent(createPosListElement(posList)); whereElement.addContent(lineElement); } else if (geometry instanceof Polygon) { final Element polygonElement = new Element("Polygon", GeoRSSModule.GML_NS); { final AbstractRing ring = ((Polygon) geometry).getExterior(); if (ring instanceof LinearRing) { final Element exteriorElement = new Element("exterior", GeoRSSModule.GML_NS); polygonElement.addContent(exteriorElement); final Element ringElement = new Element("LinearRing", GeoRSSModule.GML_NS); exteriorElement.addContent(ringElement); ringElement.addContent(createPosListElement(((LinearRing) ring).getPositionList())); } else { System.err .println("GeoRSS GML format can't handle rings of type: " + ring.getClass().getName()); } } final List<AbstractRing> interiorList = ((Polygon) geometry).getInterior(); final Iterator<AbstractRing> it = interiorList.iterator(); while (it.hasNext()) { final AbstractRing ring = it.next(); if (ring instanceof LinearRing) { final Element interiorElement = new Element("interior", GeoRSSModule.GML_NS); polygonElement.addContent(interiorElement); final Element ringElement = new Element("LinearRing", GeoRSSModule.GML_NS); interiorElement.addContent(ringElement); ringElement.addContent(createPosListElement(((LinearRing) ring).getPositionList())); } else { System.err .println("GeoRSS GML format can't handle rings of type: " + ring.getClass().getName()); } } whereElement.addContent(polygonElement); } else if (geometry instanceof Envelope) { final Envelope envelope = (Envelope) geometry; final Element envelopeElement = new Element("Envelope", GeoRSSModule.GML_NS); whereElement.addContent(envelopeElement); final Element lowerElement = new Element("lowerCorner", GeoRSSModule.GML_NS); lowerElement.addContent( String.valueOf(envelope.getMinLatitude()) + " " + String.valueOf(envelope.getMinLongitude())); envelopeElement.addContent(lowerElement); final Element upperElement = new Element("upperCorner", GeoRSSModule.GML_NS); upperElement.addContent( String.valueOf(envelope.getMaxLatitude()) + " " + String.valueOf(envelope.getMaxLongitude())); envelopeElement.addContent(upperElement); } else { System.err .println("GeoRSS GML format can't handle geometries of type: " + geometry.getClass().getName()); } }
From source file:com.rometools.modules.georss.SimpleGenerator.java
License:Apache License
@Override public void generate(final Module module, final Element element) { // this is not necessary, it is done to avoid the namespace definition // in every item. Element root = element;/*from w ww . j ava2 s. c om*/ while (root.getParent() != null && root.getParent() instanceof Element) { root = (Element) element.getParent(); } root.addNamespaceDeclaration(GeoRSSModule.SIMPLE_NS); final GeoRSSModule geoRSSModule = (GeoRSSModule) module; final AbstractGeometry geometry = geoRSSModule.getGeometry(); if (geometry instanceof Point) { final Position pos = ((Point) geometry).getPosition(); final Element pointElement = new Element("point", GeoRSSModule.SIMPLE_NS); pointElement.addContent(pos.getLatitude() + " " + pos.getLongitude()); element.addContent(pointElement); } else if (geometry instanceof LineString) { final PositionList posList = ((LineString) geometry).getPositionList(); final Element lineElement = new Element("line", GeoRSSModule.SIMPLE_NS); lineElement.addContent(posListToString(posList)); element.addContent(lineElement); } else if (geometry instanceof Polygon) { final AbstractRing ring = ((Polygon) geometry).getExterior(); if (ring instanceof LinearRing) { final PositionList posList = ((LinearRing) ring).getPositionList(); final Element polygonElement = new Element("polygon", GeoRSSModule.SIMPLE_NS); polygonElement.addContent(posListToString(posList)); element.addContent(polygonElement); } else { LOG.error("GeoRSS simple format can't handle rings of type: " + ring.getClass().getName()); } if (((Polygon) geometry).getInterior() != null && !((Polygon) geometry).getInterior().isEmpty()) { LOG.error("GeoRSS simple format can't handle interior rings (ignored)"); } } else if (geometry instanceof Envelope) { final Envelope envelope = (Envelope) geometry; final Element boxElement = new Element("box", GeoRSSModule.SIMPLE_NS); boxElement.addContent(envelope.getMinLatitude() + " " + envelope.getMinLongitude() + " " + envelope.getMaxLatitude() + " " + envelope.getMaxLongitude()); element.addContent(boxElement); } else { LOG.error("GeoRSS simple format can't handle geometries of type: " + geometry.getClass().getName()); } }
From source file:com.rometools.modules.georss.W3CGeoGenerator.java
License:Apache License
@Override public void generate(final Module module, final Element element) { // this is not necessary, it is done to avoid the namespace definition // in every item. Element root = element;/*from w ww . ja va2s . c o m*/ while (root.getParent() != null && root.getParent() instanceof Element) { root = (Element) element.getParent(); } root.addNamespaceDeclaration(GeoRSSModule.W3CGEO_NS); Element pointElement = element; if (!isShort) { pointElement = new Element("Point", GeoRSSModule.W3CGEO_NS); element.addContent(pointElement); } final GeoRSSModule geoRSSModule = (GeoRSSModule) module; final AbstractGeometry geometry = geoRSSModule.getGeometry(); if (geometry instanceof Point) { final Position pos = ((Point) geometry).getPosition(); final Element latElement = new Element("lat", GeoRSSModule.W3CGEO_NS); latElement.addContent(String.valueOf(pos.getLatitude())); pointElement.addContent(latElement); final Element lngElement = new Element("long", GeoRSSModule.W3CGEO_NS); lngElement.addContent(String.valueOf(pos.getLongitude())); pointElement.addContent(lngElement); } else { System.err.println("W3C Geo format can't handle geometries of type: " + geometry.getClass().getName()); } }