org.carrot2.util.resource
Class URLResourceWithParams

java.lang.Object
  extended by org.carrot2.util.resource.URLResourceWithParams
All Implemented Interfaces:
IResource

public class URLResourceWithParams
extends Object
implements IResource

A IResource implementation that allows URLs to be parameterized. The attribute place holders are of format: ${attribute} and will be replaced before the contents is fetched from the URL when the open(Map) method is used.


Constructor Summary
URLResourceWithParams(URL url)
          Creates an instance with the provided url;
 
Method Summary
static boolean containsAttributePlaceholder(String urlTemplate, String attributePlaceholderName)
          Returns true if the urlTemplate contains the attributePlaceholderName.
 boolean equals(Object obj)
           
static String formatAttributePlaceholder(String attributePlaceholderName)
          Returns attribute place holder based on the attribute name.
 URL getUrl()
           
 int hashCode()
           
 InputStream open()
          Opens the underlying URL without attribute substitution.
 InputStream open(Map<String,Object> attributes)
          Opens the underlying URL substituting attribute place holders beforehand.
static String substituteAttributes(String parameterizedURL, Map<String,Object> attributes)
          Performs attribute substitution.
 String toString()
           
static URLResourceWithParams valueOf(String string)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

URLResourceWithParams

public URLResourceWithParams(URL url)
Creates an instance with the provided url;

Method Detail

open

public InputStream open()
                 throws IOException
Opens the underlying URL without attribute substitution.

Specified by:
open in interface IResource
Throws:
IOException

open

public InputStream open(Map<String,Object> attributes)
                 throws IOException
Opens the underlying URL substituting attribute place holders beforehand.

Parameters:
attributes - values of attributes to be replaced in the corresponding place holders. If a place holder is of form: ${attributeX}, it will be replaced by the value found (if any) in the attributes map under the attributeX key.
Throws:
IOException

substituteAttributes

public static String substituteAttributes(String parameterizedURL,
                                          Map<String,Object> attributes)
Performs attribute substitution.


containsAttributePlaceholder

public static boolean containsAttributePlaceholder(String urlTemplate,
                                                   String attributePlaceholderName)
Returns true if the urlTemplate contains the attributePlaceholderName.


formatAttributePlaceholder

public static String formatAttributePlaceholder(String attributePlaceholderName)
Returns attribute place holder based on the attribute name.


toString

public String toString()
Overrides:
toString in class Object

equals

public final boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public final int hashCode()
Overrides:
hashCode in class Object

getUrl

public URL getUrl()

valueOf

public static URLResourceWithParams valueOf(String string)


Copyright (c) Dawid Weiss, Stanislaw Osinski