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.io.impl; 18 19 import org.jdom.Document; 20 import org.jdom.Element; 21 import org.jdom.Namespace; 22 import com.sun.syndication.feed.WireFeed; 23 24 25 /** 26 * To address issue with certain feeds (brought up by Charles Miller): 27 * 28 * "During the debacle that was the rollout of RSS2.0, this namespace was tried, 29 * and even appeared in Dave Winer's Scripting News feed for a while. It was 30 * then withdrawn, but the wonderful thing about standards is the moment you 31 * roll one out, even if it's marked as unfinished and subject to change, 32 * someone will end up stuck with it forever." 33 * 34 * Note that there is not counter part on the generator, we only generate the final RSS2 35 * 36 */ 37 public class RSS20wNSParser extends RSS20Parser { 38 private static String RSS20_URI = "http://backend.userland.com/rss2"; 39 40 public RSS20wNSParser() { 41 this("rss_2.0wNS"); 42 } 43 44 protected RSS20wNSParser(String type) { 45 super(type); 46 } 47 48 public boolean isMyType(Document document) { 49 Element rssRoot = document.getRootElement(); 50 Namespace defaultNS = rssRoot.getNamespace(); 51 boolean ok = defaultNS!=null && defaultNS.equals(getRSSNamespace()); 52 if (ok) { 53 ok = super.isMyType(document); 54 } 55 return ok; 56 } 57 58 protected Namespace getRSSNamespace() { 59 return Namespace.getNamespace(RSS20_URI); 60 } 61 62 /** 63 * After we parse the feed we put "rss_2.0" in it (so converters and generators work) 64 * this parser is a phantom. 65 * 66 */ 67 protected WireFeed parseChannel(Element rssRoot) { 68 WireFeed wFeed = super.parseChannel(rssRoot); 69 wFeed.setFeedType("rss_2.0"); 70 return wFeed; 71 } 72 73 }