org.apache.commons.feedparser.locate
Class ResourceExpander

java.lang.Object
  extended by org.apache.commons.feedparser.locate.ResourceExpander

public class ResourceExpander
extends Object

Version:
$Id: ResourceExpander.java 373622 2006-01-30 22:53:00Z mvdb $
Author:
Kevin A. Burton

Field Summary
protected static Pattern schemePattern
          A regexp to determine if a URL has a scheme, such as "http://foo.com".
 
Constructor Summary
ResourceExpander()
           
 
Method Summary
static String expand(String resource, String link)
          Expand a link relavant to the current site.
static String getBase(String resource)
          Get the base of this URL.
static String getDomain(String resource)
          Given a URL get the domain name.
static String getSite(String resource)
          Get the site for this resource.
static boolean hasScheme(String resource)
          Determines if the given resource has a scheme.
static boolean isExpanded(String resource)
          Return true if the given link is ALREADY relativized..
static boolean isValidScheme(String resource)
          Return true if this is an valid scheme and should be expanded.
static void main(String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

schemePattern

protected static Pattern schemePattern
A regexp to determine if a URL has a scheme, such as "http://foo.com".

Constructor Detail

ResourceExpander

public ResourceExpander()
Method Detail

expand

public static String expand(String resource,
                            String link)
Expand a link relavant to the current site. This takes care of links such as /foo.html -> http://site.com/base/foo.html foo.html -> http://site.com/base/foo.html Links should *always* be expanded before they are used. This is because if we use the URL http://site.com/base then we don't know if it's a directory or a file. http://site.com/base/ would be a directory. Note that all resource URLs will have correct trailing slashes. If the URL does not end with / then it is a file URL and not a directory.

Parameters:
resource - The absolute base URL that will be used to expand the link, such as "http://www.codinginparadise.org".
link - The link to possibly expand, such as "/index.rdf" or "http://www.somehost.com/somepage.html".

isExpanded

public static boolean isExpanded(String resource)
Return true if the given link is ALREADY relativized..


isValidScheme

public static boolean isValidScheme(String resource)
Return true if this is an valid scheme and should be expanded.


hasScheme

public static boolean hasScheme(String resource)
Determines if the given resource has a scheme. (i.e. does it start with "http://foo.com" or does it just have "foo.com").


getSite

public static String getSite(String resource)
Get the site for this resource. For example: http://www.foo.com/directory/index.html we will return http://www.foo.com for file: URLs we return file://


getDomain

public static String getDomain(String resource)
Given a URL get the domain name.


getBase

public static String getBase(String resource)
Get the base of this URL. For example if we are given: http://www.foo.com/directory/index.html we will return http://www.foo.com/directory


main

public static void main(String[] args)
                 throws Exception
Throws:
Exception


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.