List of usage examples for org.jdom2 Element Element
public Element(final String name, final String uri)
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 ww. j a v a 2 s .c o 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 w w w. j av a 2 s . c om 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;// w w w . ja va 2 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 va 2 s . 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()); } }
From source file:com.rometools.modules.itunes.io.ITunesGenerator.java
License:Open Source License
protected Element generateSimpleElement(final String name, final String value) { final Element element = new Element(name, NAMESPACE); element.addContent(value);//from w w w .j a v a 2 s .c o m return element; }
From source file:com.rometools.modules.mediarss.io.MediaModuleGenerator.java
License:Open Source License
public void generateContent(final MediaContent c, final Element e) { final Element mc = new Element("content", NS); addNotNullAttribute(mc, "medium", c.getMedium()); addNotNullAttribute(mc, "channels", c.getAudioChannels()); addNotNullAttribute(mc, "bitrate", c.getBitrate()); addNotNullAttribute(mc, "duration", c.getDuration()); addNotNullAttribute(mc, "expression", c.getExpression()); addNotNullAttribute(mc, "fileSize", c.getFileSize()); addNotNullAttribute(mc, "framerate", c.getFramerate()); addNotNullAttribute(mc, "height", c.getHeight()); addNotNullAttribute(mc, "lang", c.getLanguage()); addNotNullAttribute(mc, "samplingrate", c.getSamplingrate()); addNotNullAttribute(mc, "type", c.getType()); addNotNullAttribute(mc, "width", c.getWidth()); if (c.isDefaultContent()) { addNotNullAttribute(mc, "isDefault", "true"); }//from www . j a v a2s . co m if (c.getReference() instanceof UrlReference) { addNotNullAttribute(mc, "url", c.getReference()); generatePlayer(c.getPlayer(), mc); } else { generatePlayer(c.getPlayer(), mc); } generateMetadata(c.getMetadata(), mc); e.addContent(mc); }
From source file:com.rometools.modules.mediarss.io.MediaModuleGenerator.java
License:Open Source License
public void generateGroup(final MediaGroup g, final Element e) { final Element t = new Element("group", NS); final MediaContent[] c = g.getContents(); for (final MediaContent element : c) { generateContent(element, t);/*from w ww .jav a 2 s . c om*/ } generateMetadata(g.getMetadata(), t); e.addContent(t); }
From source file:com.rometools.modules.mediarss.io.MediaModuleGenerator.java
License:Open Source License
public void generateMetadata(final Metadata m, final Element e) { if (m == null) { return;/*from w w w . j ava 2s. co m*/ } final Category[] cats = m.getCategories(); for (final Category cat : cats) { final Element c = generateSimpleElement("category", cat.getValue()); addNotNullAttribute(c, "scheme", cat.getScheme()); addNotNullAttribute(c, "label", cat.getLabel()); e.addContent(c); } final Element copyright = addNotNullElement(e, "copyright", m.getCopyright()); addNotNullAttribute(copyright, "url", m.getCopyrightUrl()); final Credit[] creds = m.getCredits(); for (final Credit cred : creds) { final Element c = generateSimpleElement("credit", cred.getName()); addNotNullAttribute(c, "role", cred.getRole()); addNotNullAttribute(c, "scheme", cred.getScheme()); e.addContent(c); } final Element desc = addNotNullElement(e, "description", m.getDescription()); addNotNullAttribute(desc, "type", m.getDescriptionType()); if (m.getHash() != null) { final Element hash = addNotNullElement(e, "hash", m.getHash().getValue()); addNotNullAttribute(hash, "algo", m.getHash().getAlgorithm()); } final String[] keywords = m.getKeywords(); if (keywords.length > 0) { String keyword = keywords[0]; for (int i = 1; i < keywords.length; i++) { keyword += ", " + keywords[i]; } addNotNullElement(e, "keywords", keyword); } final Rating[] rats = m.getRatings(); for (final Rating rat2 : rats) { final Element rat = addNotNullElement(e, "rating", rat2.getValue()); addNotNullAttribute(rat, "scheme", rat2.getScheme()); if (rat2.equals(Rating.ADULT)) { addNotNullElement(e, "adult", "true"); } else if (rat2.equals(Rating.NONADULT)) { addNotNullElement(e, "adult", "false"); } } final Text[] text = m.getText(); for (final Text element : text) { final Element t = addNotNullElement(e, "text", element.getValue()); addNotNullAttribute(t, "type", element.getType()); addNotNullAttribute(t, "start", element.getStart()); addNotNullAttribute(t, "end", element.getEnd()); } final Thumbnail[] thumbs = m.getThumbnail(); for (final Thumbnail thumb : thumbs) { final Element t = new Element("thumbnail", NS); addNotNullAttribute(t, "url", thumb.getUrl()); addNotNullAttribute(t, "width", thumb.getWidth()); addNotNullAttribute(t, "height", thumb.getHeight()); addNotNullAttribute(t, "time", thumb.getTime()); e.addContent(t); } final Element title = addNotNullElement(e, "title", m.getTitle()); addNotNullAttribute(title, "type", m.getTitleType()); final Restriction[] r = m.getRestrictions(); for (final Restriction element : r) { final Element res = addNotNullElement(e, "restriction", element.getValue()); addNotNullAttribute(res, "type", element.getType()); addNotNullAttribute(res, "relationship", element.getRelationship()); } }
From source file:com.rometools.modules.mediarss.io.MediaModuleGenerator.java
License:Open Source License
public void generatePlayer(final PlayerReference p, final Element e) { if (p == null) { return;/*from ww w . jav a 2s . c om*/ } final Element t = new Element("player", NS); addNotNullAttribute(t, "url", p.getUrl()); addNotNullAttribute(t, "width", p.getWidth()); addNotNullAttribute(t, "height", p.getHeight()); e.addContent(t); }
From source file:com.rometools.modules.mediarss.io.MediaModuleGenerator.java
License:Open Source License
protected Element generateSimpleElement(final String name, final String value) { final Element element = new Element(name, NS); element.addContent(value);/*from w w w. ja v a2s. c o m*/ return element; }