List of usage examples for org.jdom2 Element addNamespaceDeclaration
public boolean addNamespaceDeclaration(final Namespace additionalNamespace)
From source file:com.googlecode.mipnp.mediaserver.cds.DidlLiteDocument.java
License:Open Source License
public DidlLiteDocument(URL mediaLocation, String filter) { this.mediaLocation = mediaLocation; this.filter = filter; Element root = new Element("DIDL-Lite", NS_DEFAULT); root.addNamespaceDeclaration(NS_DC); root.addNamespaceDeclaration(NS_UPNP); this.document = new Document(root); }
From source file:com.kixeye.kixmpp.jdom.StAXElementBuilder.java
License:Apache License
/** * Processes the current event on a stream reader. * /*from w ww . ja v a2 s . c om*/ * @param streamReader * @throws JDOMException */ public void process(XMLStreamReader2 streamReader) throws JDOMException { switch (streamReader.getEventType()) { case XMLStreamReader2.START_ELEMENT: { // build the element Namespace namespace = getNamespace(streamReader.getPrefix(), streamReader.getNamespaceURI()); Element element = null; if (namespace == null) { element = builderFactory.element(streamReader.getLocalName()); } else { element = builderFactory.element(streamReader.getLocalName(), getNamespace(streamReader.getPrefix(), streamReader.getNamespaceURI())); } if (rootElement == null) { rootElement = element; currentElement = element; } else { currentElement.addContent(element); currentElement = element; } // set attributes for (int i = 0, len = streamReader.getAttributeCount(); i < len; i++) { namespace = getNamespace(streamReader.getAttributePrefix(i), streamReader.getAttributeNamespace(i)); Attribute attribute = null; if (namespace == null) { attribute = builderFactory.attribute(streamReader.getAttributeLocalName(i), streamReader.getAttributeValue(i), AttributeType.getAttributeType(streamReader.getAttributeType(i)), getNamespace( streamReader.getAttributePrefix(i), streamReader.getAttributeNamespace(i))); } else { attribute = builderFactory.attribute(streamReader.getAttributeLocalName(i), streamReader.getAttributeValue(i), AttributeType.getAttributeType(streamReader.getAttributeType(i))); } builderFactory.setAttribute(element, attribute); } // set namespaces for (int i = 0, len = streamReader.getNamespaceCount(); i < len; i++) { namespace = getNamespace(streamReader.getNamespacePrefix(i), streamReader.getNamespaceURI(i)); if (namespace != null) { element.addNamespaceDeclaration(namespace); } } } break; case XMLStreamReader2.END_ELEMENT: { if (currentElement != null) { currentElement = currentElement.getParentElement(); if (currentElement == null) { currentElement = rootElement; } } } break; case XMLStreamReader2.SPACE: case XMLStreamReader2.CHARACTERS: { currentElement.addContent(builderFactory.text(streamReader.getText())); } break; case XMLStreamReader2.CDATA: { currentElement.addContent(builderFactory.cdata(streamReader.getText())); } break; case XMLStreamReader2.ENTITY_REFERENCE: { currentElement.addContent(builderFactory.entityRef(streamReader.getText())); } break; case XMLStreamReader2.COMMENT: { currentElement.addContent(builderFactory.comment(streamReader.getText())); } break; case XMLStreamReader2.PROCESSING_INSTRUCTION: { currentElement.addContent( builderFactory.processingInstruction(streamReader.getPITarget(), streamReader.getPIData())); } break; case XMLStreamReader2.DTD: { currentElement.addContent(DTDParser.parse(streamReader.getText(), builderFactory)); } break; } }
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; while (root.getParent() != null && root.getParent() instanceof Element) { root = (Element) root.getParent(); }// w w w .ja va 2s . c o m 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.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; while (root.getParent() != null && root.getParent() instanceof Element) { root = (Element) element.getParent(); }/*from w ww .j a va 2 s .c o m*/ 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; while (root.getParent() != null && root.getParent() instanceof Element) { root = (Element) element.getParent(); }//ww w. j a v a2s . co m 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; while (root.getParent() != null && root.getParent() instanceof Element) { root = (Element) element.getParent(); }//from w w w . j av a2 s . c om 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
@Override public void generate(final Module module, final Element element) { Element root = element; while (root.getParent() != null && root.getParent() instanceof Element) { root = (Element) root.getParent(); }/*from w w w . j a va2s .c o m*/ root.addNamespaceDeclaration(NAMESPACE); if (!(module instanceof AbstractITunesObject)) { return; } final AbstractITunesObject itunes = (AbstractITunesObject) module; if (itunes instanceof FeedInformationImpl) { // Do Channel Specific Stuff. final FeedInformationImpl info = (FeedInformationImpl) itunes; final Element owner = generateSimpleElement("owner", ""); final Element email = generateSimpleElement("email", info.getOwnerEmailAddress()); owner.addContent(email); final Element name = generateSimpleElement("name", info.getOwnerName()); owner.addContent(name); element.addContent(owner); if (info.getImage() != null) { final Element image = generateSimpleElement("image", ""); image.setAttribute("href", info.getImage().toExternalForm()); element.addContent(image); } final List<Category> categories = info.getCategories(); for (final Category cat : categories) { final Element category = generateSimpleElement("category", ""); category.setAttribute("text", cat.getName()); if (cat.getSubcategory() != null) { final Element subcat = generateSimpleElement("category", ""); subcat.setAttribute("text", cat.getSubcategory().getName()); category.addContent(subcat); } element.addContent(category); } } else if (itunes instanceof EntryInformationImpl) { final EntryInformationImpl info = (EntryInformationImpl) itunes; if (info.getDuration() != null) { element.addContent(generateSimpleElement("duration", info.getDuration().toString())); } } if (itunes.getAuthor() != null) { element.addContent(generateSimpleElement("author", itunes.getAuthor())); } if (itunes.getBlock()) { element.addContent(generateSimpleElement("block", "")); } if (itunes.getExplicit()) { element.addContent(generateSimpleElement("explicit", "yes")); } else { element.addContent(generateSimpleElement("explicit", "no")); } if (itunes.getKeywords() != null) { final StringBuffer sb = new StringBuffer(); for (int i = 0; i < itunes.getKeywords().length; i++) { if (i != 0) { sb.append(", "); } sb.append(itunes.getKeywords()[i]); } element.addContent(generateSimpleElement("keywords", sb.toString())); } if (itunes.getSubtitle() != null) { element.addContent(generateSimpleElement("subtitle", itunes.getSubtitle())); } if (itunes.getSummary() != null) { element.addContent(generateSimpleElement("summary", itunes.getSummary())); } }
From source file:com.rometools.rome.io.impl.Atom03Generator.java
License:Open Source License
protected Element createRootElement(final Feed feed) { final Element root = new Element("feed", getFeedNamespace()); root.addNamespaceDeclaration(getFeedNamespace()); final Attribute version = new Attribute("version", getVersion()); root.setAttribute(version);// ww w. java 2 s .c om generateModuleNamespaceDefs(root); return root; }
From source file:com.rometools.rome.io.impl.Atom10Generator.java
License:Open Source License
protected Element createRootElement(final Feed feed) { final Element root = new Element("feed", getFeedNamespace()); root.addNamespaceDeclaration(getFeedNamespace()); // Attribute version = new Attribute("version", getVersion()); // root.setAttribute(version); final String xmlBase = feed.getXmlBase(); if (xmlBase != null) { root.setAttribute("base", xmlBase, Namespace.XML_NAMESPACE); }/* w ww . j a va 2 s.com*/ generateModuleNamespaceDefs(root); return root; }
From source file:com.rometools.rome.io.impl.RSS090Generator.java
License:Open Source License
protected Element createRootElement(final Channel channel) { final Element root = new Element("RDF", getRDFNamespace()); root.addNamespaceDeclaration(getFeedNamespace()); root.addNamespaceDeclaration(getRDFNamespace()); root.addNamespaceDeclaration(getContentNamespace()); generateModuleNamespaceDefs(root);/* w w w.j ava2s . com*/ return root; }