/ojc-core/component-common/axiondb/external/src/com/sun/syndication/feed/synd/impl/ConverterForRSS091Userland.java

https://bitbucket.org/ssteinmetz/openesb-components · Java · 153 lines · 109 code · 20 blank · 24 comment · 16 complexity · a4a915e3bfd492ebfa3856b5df61da8f MD5 · raw file

  1. /*
  2. * Copyright 2004 Sun Microsystems, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package com.sun.syndication.feed.synd.impl;
  18. import com.sun.syndication.feed.WireFeed;
  19. import com.sun.syndication.feed.module.DCModule;
  20. import com.sun.syndication.feed.rss.Channel;
  21. import com.sun.syndication.feed.rss.Content;
  22. import com.sun.syndication.feed.rss.Description;
  23. import com.sun.syndication.feed.rss.Image;
  24. import com.sun.syndication.feed.rss.Item;
  25. import com.sun.syndication.feed.synd.SyndFeed;
  26. import com.sun.syndication.feed.synd.SyndContent;
  27. import com.sun.syndication.feed.synd.SyndEntry;
  28. import com.sun.syndication.feed.synd.SyndImage;
  29. import com.sun.syndication.feed.synd.SyndContentImpl;
  30. import com.sun.syndication.feed.synd.SyndPerson;
  31. import java.util.*;
  32. /**
  33. */
  34. public class ConverterForRSS091Userland extends ConverterForRSS090 {
  35. public ConverterForRSS091Userland() {
  36. this("rss_0.91U");
  37. }
  38. protected ConverterForRSS091Userland(String type) {
  39. super(type);
  40. }
  41. public void copyInto(WireFeed feed,SyndFeed syndFeed) {
  42. Channel channel = (Channel) feed;
  43. super.copyInto(channel,syndFeed);
  44. syndFeed.setLanguage(channel.getLanguage()); //c
  45. syndFeed.setCopyright(channel.getCopyright()); //c
  46. Date pubDate = channel.getPubDate();
  47. if (pubDate!=null) {
  48. syndFeed.setPublishedDate(pubDate); //c
  49. } else if (channel.getLastBuildDate() != null) {
  50. syndFeed.setPublishedDate(channel.getLastBuildDate()); //c
  51. }
  52. String author = channel.getManagingEditor();
  53. if (author!=null) {
  54. List creators = ((DCModule) syndFeed.getModule(DCModule.URI)).getCreators();
  55. if (!creators.contains(author)) {
  56. Set s = new HashSet(); // using a set to remove duplicates
  57. s.addAll(creators); // DC creators
  58. s.add(author); // feed native author
  59. creators.clear();
  60. creators.addAll(s);
  61. }
  62. }
  63. }
  64. protected SyndImage createSyndImage(Image rssImage) {
  65. SyndImage syndImage = super.createSyndImage(rssImage);
  66. syndImage.setDescription(rssImage.getDescription());
  67. return syndImage;
  68. }
  69. // for rss -> synd
  70. // rss.content -> synd.content
  71. // rss.description -> synd.description
  72. protected SyndEntry createSyndEntry(Item item) {
  73. SyndEntry syndEntry = super.createSyndEntry(item);
  74. Description desc = item.getDescription();
  75. if (desc != null) {
  76. SyndContent descContent = new SyndContentImpl();
  77. descContent.setType(desc.getType());
  78. descContent.setValue(desc.getValue());
  79. syndEntry.setDescription(descContent);
  80. }
  81. Content cont = item.getContent();
  82. if (cont != null) {
  83. SyndContent content = new SyndContentImpl();
  84. content.setType(cont.getType());
  85. content.setValue(cont.getValue());
  86. List syndContents = new ArrayList();
  87. syndContents.add(content);
  88. syndEntry.setContents(syndContents);
  89. }
  90. return syndEntry;
  91. }
  92. protected WireFeed createRealFeed(String type,SyndFeed syndFeed) {
  93. Channel channel = (Channel) super.createRealFeed(type,syndFeed);
  94. channel.setLanguage(syndFeed.getLanguage()); //c
  95. channel.setCopyright(syndFeed.getCopyright()); //c
  96. channel.setPubDate(syndFeed.getPublishedDate()); //c
  97. if (syndFeed.getAuthors()!=null && syndFeed.getAuthors().size() > 0) {
  98. SyndPerson author = (SyndPerson)syndFeed.getAuthors().get(0);
  99. channel.setManagingEditor(author.getName());
  100. }
  101. return channel;
  102. }
  103. protected Image createRSSImage(SyndImage sImage) {
  104. Image image = super.createRSSImage(sImage);
  105. image.setDescription(sImage.getDescription());
  106. return image;
  107. }
  108. // for synd -> rss
  109. // synd.content -> rss.content
  110. // synd.description -> rss.description
  111. protected Item createRSSItem(SyndEntry sEntry) {
  112. Item item = super.createRSSItem(sEntry);
  113. SyndContent sContent = sEntry.getDescription();
  114. if (sContent!=null) {
  115. item.setDescription(createItemDescription(sContent));
  116. }
  117. List contents = sEntry.getContents();
  118. if (contents != null && contents.size() > 0) {
  119. SyndContent syndContent = (SyndContent)contents.get(0);
  120. Content cont = new Content();
  121. cont.setValue(syndContent.getValue());
  122. cont.setType(syndContent.getType());
  123. item.setContent(cont);
  124. }
  125. return item;
  126. }
  127. protected Description createItemDescription(SyndContent sContent) {
  128. Description desc = new Description();
  129. desc.setValue(sContent.getValue());
  130. desc.setType(sContent.getType());
  131. return desc;
  132. }
  133. }