List of usage examples for org.jdom2 Element Element
public Element(final String name, final String uri)
From source file:com.rometools.modules.base.io.CustomTagGenerator.java
License:Open Source License
@Override public void generate(final Module module, final Element element) { if (!(module instanceof CustomTags)) { return;/*from w w w . j av a2s .c o m*/ } final List<CustomTag> tags = ((CustomTags) module).getValues(); final Iterator<CustomTag> it = tags.iterator(); while (it.hasNext()) { final CustomTag tag = it.next(); if (tag.getValue() instanceof DateTimeRange) { final DateTimeRange dtr = (DateTimeRange) tag.getValue(); final Element newTag = new Element(tag.getName(), CustomTagParser.NS); newTag.setAttribute("type", "dateTimeRange"); newTag.addContent( generateSimpleElement("start", GoogleBaseParser.LONG_DT_FMT.format(dtr.getStart()))); newTag.addContent(generateSimpleElement("end", GoogleBaseParser.LONG_DT_FMT.format(dtr.getEnd()))); element.addContent(newTag); } else if (tag.getValue() instanceof ShortDate) { final ShortDate sd = (ShortDate) tag.getValue(); final Element newTag = generateSimpleElement(tag.getName(), GoogleBaseParser.SHORT_DT_FMT.format(sd)); newTag.setAttribute("type", "date"); element.addContent(newTag); } else if (tag.getValue() instanceof Date) { final Date d = (Date) tag.getValue(); final Element newTag = generateSimpleElement(tag.getName(), GoogleBaseParser.SHORT_DT_FMT.format(d)); newTag.setAttribute("type", "dateTime"); element.addContent(newTag); } else if (tag.getValue() instanceof Integer) { final Element newTag = generateSimpleElement(tag.getName(), tag.getValue().toString()); newTag.setAttribute("type", "int"); element.addContent(newTag); } else if (tag.getValue() instanceof IntUnit) { final Element newTag = generateSimpleElement(tag.getName(), tag.getValue().toString()); newTag.setAttribute("type", "intUnit"); element.addContent(newTag); } else if (tag.getValue() instanceof Float) { final Element newTag = generateSimpleElement(tag.getName(), tag.getValue().toString()); newTag.setAttribute("type", "float"); element.addContent(newTag); } else if (tag.getValue() instanceof FloatUnit) { final Element newTag = generateSimpleElement(tag.getName(), tag.getValue().toString()); newTag.setAttribute("type", "floatUnit"); element.addContent(newTag); } else if (tag.getValue() instanceof String) { final Element newTag = generateSimpleElement(tag.getName(), tag.getValue().toString()); newTag.setAttribute("type", "string"); element.addContent(newTag); } else if (tag.getValue() instanceof URL) { final Element newTag = generateSimpleElement(tag.getName(), tag.getValue().toString()); newTag.setAttribute("type", "url"); element.addContent(newTag); } else if (tag.getValue() instanceof Boolean) { final Element newTag = generateSimpleElement(tag.getName(), tag.getValue().toString()); newTag.setAttribute("type", "boolean"); element.addContent(newTag); } else if (tag.getValue() instanceof CustomTagImpl.Location) { final Element newTag = generateSimpleElement(tag.getName(), tag.getValue().toString()); newTag.setAttribute("type", "location"); element.addContent(newTag); } } }
From source file:com.rometools.modules.base.io.CustomTagGenerator.java
License:Open Source License
protected Element generateSimpleElement(final String name, final String value) { final Element element = new Element(name, CustomTagParser.NS); element.addContent(value);/* w w w. jav a 2s . c om*/ return element; }
From source file:com.rometools.modules.base.io.GoogleBaseGenerator.java
License:Open Source License
public Element generateTag(final Object o, final String tagName) { if (o instanceof URL || o instanceof Float || o instanceof Boolean || o instanceof Integer || o instanceof String || o instanceof FloatUnit || o instanceof IntUnit || o instanceof GenderEnumeration || o instanceof PaymentTypeEnumeration || o instanceof PriceTypeEnumeration || o instanceof CurrencyEnumeration || o instanceof Size || o instanceof YearType) { return generateSimpleElement(tagName, o.toString()); } else if (o instanceof ShortDate) { return generateSimpleElement(tagName, GoogleBaseParser.SHORT_DT_FMT.format(o)); } else if (o instanceof Date) { return generateSimpleElement(tagName, GoogleBaseParser.LONG_DT_FMT.format(o)); } else if (o instanceof ShippingType) { final ShippingType st = (ShippingType) o; final Element element = new Element(tagName, GoogleBaseGenerator.NS); element.addContent(generateSimpleElement("country", st.getCountry())); element.addContent(generateSimpleElement("service", st.getService().toString())); element.addContent(generateSimpleElement("price", st.getPrice().toString())); return element; } else if (o instanceof DateTimeRange) { final DateTimeRange dtr = (DateTimeRange) o; final Element element = new Element(tagName, GoogleBaseGenerator.NS); element.addContent(generateSimpleElement("start", GoogleBaseParser.LONG_DT_FMT.format(dtr.getStart()))); element.addContent(generateSimpleElement("end", GoogleBaseParser.LONG_DT_FMT.format(dtr.getEnd()))); return element; }//w w w . j a v a2s . co m throw new RuntimeException("Unknown class type to handle: " + o.getClass().getName()); }
From source file:com.rometools.modules.base.io.GoogleBaseGenerator.java
License:Open Source License
protected Element generateSimpleElement(final String name, final String value) { final Element element = new Element(name, GoogleBaseGenerator.NS); element.addContent(value);// w w w . j a v a 2 s .c o m return element; }
From source file:com.rometools.modules.cc.io.CCModuleGenerator.java
License:Open Source License
private void generateRSS1(final CreativeCommons module, final Element element) { // throw new RuntimeException( "Generating RSS1 Feeds not currently Supported."); LOG.debug(element.getName());/* w ww. j a va 2 s .co m*/ if (element.getName().equals("channel")) { // Do all licenses list. final License[] all = module.getAllLicenses(); for (final License element2 : all) { final Element license = new Element("License", RSS1); license.setAttribute("about", element2.getValue(), RDF); final License.Behaviour[] permits = element2.getPermits(); for (int j = 0; permits != null && j < permits.length; j++) { final Element permit = new Element("permits", RSS1); permit.setAttribute("resource", permits[j].toString(), RDF); license.addContent(permit); } final License.Behaviour[] requires = element2.getPermits(); for (int j = 0; requires != null && j < requires.length; j++) { final Element permit = new Element("requires", RSS1); permit.setAttribute("resource", permits[j].toString(), RDF); license.addContent(permit); } LOG.debug("Is Root? {}", element.getParentElement()); element.getParentElement().addContent(license); } } // Do local licenses final License[] licenses = module.getLicenses(); for (final License license2 : licenses) { final Element license = new Element("license", RSS1); license.setAttribute("resource", license2.getValue(), RDF); element.addContent(license); } }
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 va 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 w ww . ja 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);//from w w w.j a v a 2 s . c om 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);// w w w . ja v a2 s. c o m return element; }
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);//from w w w .j a va2 s. c om return element; }