List of usage examples for org.jdom2 Attribute Attribute
public Attribute(final String name, final String value)
Attribute
with the specified (local) name and value, and does not place the attribute in a Namespace
. From source file:com.rometools.rome.io.impl.RSS094Generator.java
License:Open Source License
@Override protected void populateItem(final Item item, final Element eItem, final int index) { super.populateItem(item, eItem, index); final Description description = item.getDescription(); if (description != null && description.getType() != null) { final Element eDescription = eItem.getChild("description", getFeedNamespace()); eDescription.setAttribute(new Attribute("type", description.getType())); }//from ww w . ja v a2s . c o m eItem.removeChild("expirationDate", getFeedNamespace()); }
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);// www. j a va2s .c o m generateModuleNamespaceDefs(root); 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); }//from w ww . j a v a 2s . c o 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); }//from www .j ava 2s . com 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 ww w. j a v a 2s.c o 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 .ja va2 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 ww.j a va 2 s. c o m 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); }/*from w w w .j a v a 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); }// w ww. jav a 2 s. com 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;// ww w .ja v a 2 s .c o 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()); } } }