com.planetalia.dynject.sources
Class StructuredContentSource

java.lang.Object
  extended by com.planetalia.dynject.sources.StructuredContentSource
All Implemented Interfaces:
IValueSource<java.lang.String>

public class StructuredContentSource
extends java.lang.Object
implements IValueSource<java.lang.String>

Represents a property source that takes a String as a single source and a map of (name,regexp) pairs. The value of the property is considered to be the first group capture of the regular expression corresponding the property name. This source is mainly useful for screen scraping

Author:
Alexander Hristov

Constructor Summary
StructuredContentSource(java.lang.String content, java.util.Map<java.lang.String,java.lang.String> regexps)
          Creates a structured content source that uses the specified content and regexp map
 
Method Summary
 ClassPreferences getPropertyClass(java.lang.String propertyName)
          Returns the class preferences for a property
 java.util.Set<java.lang.String> getPropertyNames()
          Returns the set of all existing properties at the time of invocation.
 java.lang.Object getValue(java.lang.String propertyName)
          Provides the value of a specific property
 boolean propertyExists(java.lang.String propertyName)
          Checks whether a specific property exists.
 void setValue(java.lang.String propertyName, java.lang.String value)
          Sets the value of a specific property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StructuredContentSource

public StructuredContentSource(java.lang.String content,
                               java.util.Map<java.lang.String,java.lang.String> regexps)
Creates a structured content source that uses the specified content and regexp map

Parameters:
content - Content from which the property values will be extracted
regexps - Map associating the name of each property with a regular expression whose first capture group captures the value of the property by using the underlying content.
Method Detail

getValue

public java.lang.Object getValue(java.lang.String propertyName)
Description copied from interface: IValueSource
Provides the value of a specific property

Specified by:
getValue in interface IValueSource<java.lang.String>
Parameters:
propertyName - Name of the requested property. Assumed to exist.
Returns:
Property value

propertyExists

public boolean propertyExists(java.lang.String propertyName)
Description copied from interface: IValueSource
Checks whether a specific property exists. Not that a nonexistant property and a proprerty with a null value are not the same situation

Specified by:
propertyExists in interface IValueSource<java.lang.String>
Parameters:
propertyName - Name of the requested property
Returns:
True if the property exists, false otherwise

getPropertyClass

public ClassPreferences getPropertyClass(java.lang.String propertyName)
Description copied from interface: IValueSource
Returns the class preferences for a property

Specified by:
getPropertyClass in interface IValueSource<java.lang.String>
Parameters:
propertyName - Name of the property
Returns:
List of class preferences for that property

getPropertyNames

public java.util.Set<java.lang.String> getPropertyNames()
Description copied from interface: IValueSource
Returns the set of all existing properties at the time of invocation.

Specified by:
getPropertyNames in interface IValueSource<java.lang.String>
Returns:
Set of property names

setValue

public void setValue(java.lang.String propertyName,
                     java.lang.String value)
Description copied from interface: IValueSource
Sets the value of a specific property. It's the callers responsability to provide a correct data type for that property. This is an optional operation. Some sources do not support writing properties to them

Specified by:
setValue in interface IValueSource<java.lang.String>
Parameters:
propertyName - Name of the requested property.
value - Property value.