001 /* 002 * Copyright 1999,2004 The Apache Software Foundation. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package org.apache.commons.feedparser.locate.blogservice; 018 019 import org.apache.commons.feedparser.FeedParserException; 020 import org.apache.commons.feedparser.locate.*; 021 022 import java.util.regex.*; 023 024 /** 025 * Models the PMachine blog service, encapsulating whether a given weblog 026 * is this type of service and where it usually keeps its feeds. 027 * 028 * @author Brad Neuberg, bkn3@columbia.edu 029 */ 030 public class PMachine extends BlogService { 031 032 /** A pattern used to discover PMachine blogs. */ 033 private static Pattern pmachinePattern = 034 Pattern.compile("pmachine", Pattern.CASE_INSENSITIVE); 035 036 /** Returns whether we can trust the results of this blog service's 037 * autodiscovery links. For example, TextAmerica returns invalid 038 * autodiscovery results. 039 */ 040 public boolean hasValidAutoDiscovery() { 041 return true; 042 } 043 044 /** Returns whether we should follow HTTP redirects for this blog service. 045 * Some services don't implement HTTP redirects correctly, while others, 046 * like Xanga, require it. 047 */ 048 public boolean followRedirects() { 049 return false; 050 } 051 052 /** Determines if the weblog at the given resource and with the given 053 * content is this blog service. 054 * @param resource A full URI to this resource, such as 055 * "http://www.codinginparadise.org". 056 * @param content The full HTML content at the resource's URL. 057 * @throws FeedParserException Thrown if an error occurs while 058 * determining the type of this weblog. 059 */ 060 public boolean isThisService(String resource, String content) 061 throws FeedParserException { 062 boolean results = false; 063 064 Matcher pmachineMatcher = pmachinePattern.matcher(resource); 065 066 results = pmachineMatcher.find(); 067 068 return results; 069 } 070 071 /** 072 * Returns an array of FeedReferences that contains information on the 073 * usual locations this blog service contains its feed. The feeds should 074 * be ordered by quality, so that higher quality feeds come before lower 075 * quality ones (i.e. you would want to have an Atom FeedReference 076 * object come before an RSS 0.91 FeedReference object in this list). 077 * @param resource A URL to the given weblog that might be used to build 078 * up where feeds are usually located. 079 * @param content The full content of the resource URL, which might 080 * be useful to determine where feeds are usually located. This can be 081 * null. 082 * @throws FeedParserException Thrown if an error occurs while trying 083 * to determine the usual locations of feeds for this service. 084 */ 085 public FeedReference[] getFeedLocations(String resource, 086 String content) 087 throws FeedParserException { 088 FeedReference pmachineLocations[] = 089 { new FeedReference("index.xml", FeedReference.RSS_MEDIA_TYPE) }; 090 091 return pmachineLocations; 092 } 093 }