List of usage examples for org.jdom2 Element setAttribute
public Element setAttribute(final Attribute attribute)
This sets an attribute value for this element.
From source file:com.sun.syndication.io.impl.Atom03Generator.java
License:Open Source License
protected Element createRootElement(Feed feed) { Element root = new Element("feed", getFeedNamespace()); root.addNamespaceDeclaration(getFeedNamespace()); Attribute version = new Attribute("version", getVersion()); root.setAttribute(version); generateModuleNamespaceDefs(root);/*from w w w .j a v a2 s . c om*/ return root; }
From source file:com.sun.syndication.io.impl.Atom03Generator.java
License:Open Source License
protected Element generateLinkElement(Link link) { Element linkElement = new Element("link", getFeedNamespace()); if (link.getRel() != null) { Attribute relAttribute = new Attribute("rel", link.getRel().toString()); linkElement.setAttribute(relAttribute); }//w w w .j a va 2 s . co m if (link.getType() != null) { Attribute typeAttribute = new Attribute("type", link.getType()); linkElement.setAttribute(typeAttribute); } if (link.getHref() != null) { Attribute hrefAttribute = new Attribute("href", link.getHref()); linkElement.setAttribute(hrefAttribute); } return linkElement; }
From source file:com.sun.syndication.io.impl.Atom03Generator.java
License:Open Source License
protected Element generateTagLineElement(Content tagline) { Element taglineElement = new Element("tagline", getFeedNamespace()); if (tagline.getType() != null) { Attribute typeAttribute = new Attribute("type", tagline.getType()); taglineElement.setAttribute(typeAttribute); }/*ww w .j a v a2 s. c om*/ if (tagline.getValue() != null) { taglineElement.addContent(tagline.getValue()); } return taglineElement; }
From source file:com.sun.syndication.io.impl.Atom03Generator.java
License:Open Source License
protected void fillContentElement(Element contentElement, Content content) throws FeedException { if (content.getType() != null) { Attribute typeAttribute = new Attribute("type", content.getType()); contentElement.setAttribute(typeAttribute); }/*from w w w . j a v a 2s . co m*/ String mode = content.getMode(); if (mode != null) { Attribute modeAttribute = new Attribute("mode", content.getMode().toString()); contentElement.setAttribute(modeAttribute); } if (content.getValue() != null) { if (mode == null || mode.equals(Content.ESCAPED)) { contentElement.addContent(content.getValue()); } else if (mode.equals(Content.BASE64)) { contentElement.addContent(Base64.encode(content.getValue())); } else if (mode.equals(Content.XML)) { StringBuffer tmpDocString = new StringBuffer("<tmpdoc>"); tmpDocString.append(content.getValue()); tmpDocString.append("</tmpdoc>"); StringReader tmpDocReader = new StringReader(tmpDocString.toString()); Document tmpDoc; try { SAXBuilder saxBuilder = new SAXBuilder(); tmpDoc = saxBuilder.build(tmpDocReader); } catch (Exception ex) { throw new FeedException("Invalid XML", ex); } List children = tmpDoc.getRootElement().removeContent(); contentElement.addContent(children); } } }
From source file:com.sun.syndication.io.impl.Atom03Generator.java
License:Open Source License
protected Element generateGeneratorElement(Generator generator) { Element generatorElement = new Element("generator", getFeedNamespace()); if (generator.getUrl() != null) { Attribute urlAttribute = new Attribute("url", generator.getUrl()); generatorElement.setAttribute(urlAttribute); }/*from w w w . j av a 2 s .c o m*/ if (generator.getVersion() != null) { Attribute versionAttribute = new Attribute("version", generator.getVersion()); generatorElement.setAttribute(versionAttribute); } if (generator.getValue() != null) { generatorElement.addContent(generator.getValue()); } return generatorElement; }
From source file:com.sun.syndication.io.impl.Atom10Generator.java
License:Open Source License
protected Element generateCategoryElement(Category cat) { Element catElement = new Element("category", getFeedNamespace()); if (cat.getTerm() != null) { Attribute termAttribute = new Attribute("term", cat.getTerm()); catElement.setAttribute(termAttribute); }/*from w w w . jav a 2s . c om*/ if (cat.getLabel() != null) { Attribute labelAttribute = new Attribute("label", cat.getLabel()); catElement.setAttribute(labelAttribute); } if (cat.getScheme() != null) { Attribute schemeAttribute = new Attribute("scheme", cat.getScheme()); catElement.setAttribute(schemeAttribute); } return catElement; }
From source file:com.sun.syndication.io.impl.Atom10Generator.java
License:Open Source License
protected Element generateLinkElement(Link link) { Element linkElement = new Element("link", getFeedNamespace()); if (link.getRel() != null) { Attribute relAttribute = new Attribute("rel", link.getRel()); linkElement.setAttribute(relAttribute); }/*w w w . java 2 s .co m*/ if (link.getType() != null) { Attribute typeAttribute = new Attribute("type", link.getType()); linkElement.setAttribute(typeAttribute); } if (link.getHref() != null) { Attribute hrefAttribute = new Attribute("href", link.getHref()); linkElement.setAttribute(hrefAttribute); } if (link.getHreflang() != null) { Attribute hreflangAttribute = new Attribute("hreflang", link.getHreflang()); linkElement.setAttribute(hreflangAttribute); } if (link.getTitle() != null) { Attribute title = new Attribute("title", link.getTitle()); linkElement.setAttribute(title); } if (link.getLength() != 0) { Attribute lenght = new Attribute("length", Long.toString(link.getLength())); linkElement.setAttribute(lenght); } return linkElement; }
From source file:com.sun.syndication.io.impl.Atom10Generator.java
License:Open Source License
protected Element generateTagLineElement(Content tagline) { Element taglineElement = new Element("subtitle", getFeedNamespace()); if (tagline.getType() != null) { Attribute typeAttribute = new Attribute("type", tagline.getType()); taglineElement.setAttribute(typeAttribute); }/*from w w w. j a va2s . c om*/ if (tagline.getValue() != null) { taglineElement.addContent(tagline.getValue()); } return taglineElement; }
From source file:com.sun.syndication.io.impl.Atom10Generator.java
License:Open Source License
protected void fillContentElement(Element contentElement, Content content) throws FeedException { String type = content.getType(); String atomType = type;//from w w w . jav a2 s .co m if (type != null) { // Fix for issue #39 "Atom 1.0 Text Types Not Set Correctly" // we're not sure who set this value, so ensure Atom types are used if ("text/plain".equals(type)) atomType = Content.TEXT; else if ("text/html".equals(type)) atomType = Content.HTML; else if ("application/xhtml+xml".equals(type)) atomType = Content.XHTML; Attribute typeAttribute = new Attribute("type", atomType); contentElement.setAttribute(typeAttribute); } String href = content.getSrc(); if (href != null) { Attribute srcAttribute = new Attribute("src", href); contentElement.setAttribute(srcAttribute); } if (content.getValue() != null) { if (atomType != null && (atomType.equals(Content.XHTML) || (atomType.indexOf("/xml")) != -1 || (atomType.indexOf("+xml")) != -1)) { StringBuffer tmpDocString = new StringBuffer("<tmpdoc>"); tmpDocString.append(content.getValue()); tmpDocString.append("</tmpdoc>"); StringReader tmpDocReader = new StringReader(tmpDocString.toString()); Document tmpDoc; try { SAXBuilder saxBuilder = new SAXBuilder(); tmpDoc = saxBuilder.build(tmpDocReader); } catch (Exception ex) { throw new FeedException("Invalid XML", ex); } List children = tmpDoc.getRootElement().removeContent(); contentElement.addContent(children); } else { // must be type html, text or some other non-XML format // JDOM will escape property for XML contentElement.addContent(content.getValue()); } } }
From source file:com.sun.syndication.io.impl.Atom10Generator.java
License:Open Source License
protected Element generateGeneratorElement(Generator generator) { Element generatorElement = new Element("generator", getFeedNamespace()); if (generator.getUrl() != null) { Attribute urlAttribute = new Attribute("uri", generator.getUrl()); generatorElement.setAttribute(urlAttribute); }/*from w ww .ja v a 2 s . c o m*/ if (generator.getVersion() != null) { Attribute versionAttribute = new Attribute("version", generator.getVersion()); generatorElement.setAttribute(versionAttribute); } if (generator.getValue() != null) { generatorElement.addContent(generator.getValue()); } return generatorElement; }