info.textgrid.utils.linkrewriter
Class AbstractReplacement

java.lang.Object
  extended by info.textgrid.utils.linkrewriter.AbstractReplacement
Direct Known Subclasses:
TokenReplacement

public abstract class AbstractReplacement
extends Object

The base class for replacements used in the link rewriter.

A replacement is responsible for replacing one link in the source file with the destination link.

Author:
vitt

Field Summary
Modifier and Type Field and Description
protected  String from
           
protected  String to
           
 
Constructor Summary
Constructor and Description
AbstractReplacement(String from, String to)
          Creates a replacement that replaces the URL specified by from with the URL specified by to.
 
Method Summary
Modifier and Type Method and Description
static String apply(List<? extends AbstractReplacement> replacements, String s)
           
abstract  String apply(String in)
          applies this replacement to the given string.
static
<T extends AbstractReplacement>
List<T>
create(Class<T> replacementType, ImportMapping mapping, boolean export)
          Creates a list of replacements that can be applied to strings.
static
<T extends AbstractReplacement>
T
create(Class<T> replacementType, ImportObject object, boolean export)
          This is a convenience method that instantiates a conforming replacement implementation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

from

protected final String from

to

protected final String to
Constructor Detail

AbstractReplacement

public AbstractReplacement(String from,
                           String to)
Creates a replacement that replaces the URL specified by from with the URL specified by to. Attention: All subclasses must implement a constructor with this signature or creating them using create(Class, ImportObject, boolean) or create(Class, ImportMapping, boolean) fails!

Method Detail

apply

public abstract String apply(String in)
applies this replacement to the given string.


create

public static <T extends AbstractReplacement> List<T> create(Class<T> replacementType,
                                                             ImportMapping mapping,
                                                             boolean export)
Creates a list of replacements that can be applied to strings.

Type Parameters:
T - The replacement implementation to use.
Parameters:
replacementType - The class of implementation to use
mapping - The mapping to implement
export - If true, replace from textgrid url to local url
Returns:
a list of replacement classes (of the class passed in) applying the correct transformation

create

public static <T extends AbstractReplacement> T create(Class<T> replacementType,
                                                       ImportObject object,
                                                       boolean export)
                                            throws IllegalArgumentException,
                                                   IllegalStateException
This is a convenience method that instantiates a conforming replacement implementation.

Type Parameters:
T - The type of replacement to instantiate
Parameters:
replacementType - the replacement implementation
object - The mapping object used for the instantiation
export - whether this is an export type replacement (from textgrid: uri to local uri)
Returns:
an instance of the class specified by replacementType that represents a replacement for this
Throws:
IllegalArgumentException - when the class passed in doesn't conform to the specification
IllegalStateException - when something else goes wrong during instantiation: See the nested exception for details.

apply

public static String apply(List<? extends AbstractReplacement> replacements,
                           String s)


Copyright © 2012 TextGrid. All Rights Reserved.