public class

ChanLocator

extends Object
java.lang.Object
   ↳ chan.content.ChanLocator

Class Overview

Provides URI handling and building.

In the first you must declare chan hosts. You can do this using addChanHost(String) method. If you add more than one host, user can choice one of them in preferences.

If you want to add special host that user might not choice, use addSpecialChanHost(String). This method is used for special hosts like JSON API or host for static data, for example.

There is the list of methods you must override:

URI building with preferred configuration provided by the following methods:

Summary

Nested Classes
enum ChanLocator.HttpsMode

HTTPS mode, used in setHttpsMode(HttpsMode) method. 

class ChanLocator.NavigationData

Navigation data holder. 

Public Constructors
ChanLocator()
Public Methods
final void addChanHost(String host)

Declares host as chan host.

final void addConvertableChanHost(String host)

Declares host as chan host.

final void addSpecialChanHost(String host)

Declares host as chan host.

final Uri buildPath(String... segments)

Builds URI with given path segments and preferred host and scheme.

final Uri buildPathWithHost(String host, String... segments)

Builds URI with given host and path segments and preferred scheme.

final Uri buildPathWithSchemeHost(boolean useHttps, String host, String... segments)

Builds URI with given scheme, host and path segments.

final Uri buildQuery(String path, String... alternation)

Builds URI with given path and parameters and preferred host and scheme.

final Uri buildQueryWithHost(String host, String path, String... alternation)

Builds URI with given host, path and parameters and preferred scheme.

final Uri buildQueryWithSchemeHost(boolean useHttps, String host, String path, String... alternation)

Builds URI with given scheme, host, path and parameters.

String createAttachmentForcedName(Uri fileUri)

Calls when client intend to obtain a file name from URI.

Uri createBoardUri(String boardName, int pageNumber)

Calls when client intend to create board URI.

Uri createPostUri(String boardName, String threadNumber, String postNumber)

Calls when client intend to create thread URI with anchor to post.

Uri createThreadUri(String boardName, String threadNumber)

Calls when client intend to create thread URI.

static <T extends ChanLocator> T get(Object object)

Return linked ChanLocator instance.

String getBoardName(Uri uri)

Returns board name from given URI.

final String getFileExtension(String path)

Returns extension of file with given path.

final String getGroupValue(String from, Pattern pattern, int groupIndex)

Finds given pattern in string and returns group by index.

String getPostNumber(Uri uri)

Returns post number from given URI.

String getThreadNumber(Uri uri)

Returns thread number from given URI.

ChanLocator.NavigationData handleUriClickSpecial(Uri uri)

Calls when client intend to handle link click.

boolean isAttachmentUri(Uri uri)

Returns whether URI is attachment URI.

final boolean isAudioExtension(String path)

Returns whether path has audio extension.

boolean isBoardUri(Uri uri)

Returns whether URI is board URI.

final boolean isChanHostOrRelative(Uri uri)

Returns whether URI's host is chan host or URI is relative (URI without scheme and host).

final boolean isImageExtension(String path)

Returns whether path has image extension.

final boolean isPathMatches(Uri uri, Pattern pattern)

Returns whether URI's path matches to given pattern.

boolean isThreadUri(Uri uri)

Returns whether URI is thread URI.

final boolean isUseHttps()

Returns whether HTTPS enabled in preferences.

final boolean isVideoExtension(String path)

Returns whether path has video extension.

final void setHttpsMode(ChanLocator.HttpsMode httpsMode)

Changes default HTTPS mode.

[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ChanLocator ()

Public Methods

public final void addChanHost (String host)

Declares host as chan host. This host might be default host in buildPath(String) and buildQuery(String, String) methods. If you declare multiple hosts, user can choice one of them in preferences. The first declared host will be chosen by default.

For example, a chan has 3 addresses: addr1.com, addr2.com, addr3.com. If user choose addr2.com in preferences, URIs with the rest addresses will be converted to addr2.com.

Parameters
host String

public final void addConvertableChanHost (String host)

Declares host as chan host. Unlike addChanHost(String) user can't choice this host in preferences, but it still can be converted. For example, it can be useful for old domains that don't work now.

Parameters
host String

public final void addSpecialChanHost (String host)

Declares host as chan host. Unlike addChanHost(String) user can't choice this host in preferences and and can't be converted. For example, it can be useful for special hosts like JSON API or static data.

Parameters
host String

public final Uri buildPath (String... segments)

Builds URI with given path segments and preferred host and scheme.

Parameters
segments String: Path segments.
Returns
Uri URI.

public final Uri buildPathWithHost (String host, String... segments)

Builds URI with given host and path segments and preferred scheme.

Parameters
host String: URI host.
segments String: Path segments.
Returns
Uri URI.

public final Uri buildPathWithSchemeHost (boolean useHttps, String host, String... segments)

Builds URI with given scheme, host and path segments.

Parameters
useHttps boolean: Defines whether use HTTPS or not.
host String: URI host.
segments String: Path segments.
Returns
Uri URI.

public final Uri buildQuery (String path, String... alternation)

Builds URI with given path and parameters and preferred host and scheme.

Parameters
path String: URI path.
alternation String: Alternation of param's names and values (name, value, name, value...).
Returns
Uri URI.

public final Uri buildQueryWithHost (String host, String path, String... alternation)

Builds URI with given host, path and parameters and preferred scheme.

Parameters
host String: URI host.
path String: URI path.
alternation String: Alternation of param's names and values (name, value, name, value...).
Returns
Uri URI.

public final Uri buildQueryWithSchemeHost (boolean useHttps, String host, String path, String... alternation)

Builds URI with given scheme, host, path and parameters.

Parameters
useHttps boolean: Defines whether use HTTPS or not.
host String: URI host.
path String: URI path.
alternation String: Alternation of param's names and values (name, value, name, value...).
Returns
Uri URI.

public String createAttachmentForcedName (Uri fileUri)

Calls when client intend to obtain a file name from URI. By default client obtains a name from last path segment of URI. You can override this behavior using this method.

Parameters
fileUri Uri: file URI
Returns
String File name.

public Uri createBoardUri (String boardName, int pageNumber)

Calls when client intend to create board URI. You must override this method.

Parameters
boardName String: Board name.
pageNumber int: Number of page, might be PAGE_NUMBER_CATALOG.
Returns
Uri Board URI.

public Uri createPostUri (String boardName, String threadNumber, String postNumber)

Calls when client intend to create thread URI with anchor to post. You must override this method.

Parameters
boardName String: Board name.
threadNumber String: Thread number.
postNumber String: Post number.
Returns
Uri Post URI.

public Uri createThreadUri (String boardName, String threadNumber)

Calls when client intend to create thread URI. You must override this method.

Parameters
boardName String: Board name.
threadNumber String: Thread number.
Returns
Uri Thread URI.

public static T get (Object object)

Return linked ChanLocator instance.

Parameters
object Object: Linked object: ChanConfiguration, ChanPerformer, ChanLocator or ChanMarkup.
Returns
T ChanLocator instance.

public String getBoardName (Uri uri)

Returns board name from given URI. You must override this method.

Parameters
uri Uri: URI to inspect.
Returns
String Board name.

public final String getFileExtension (String path)

Returns extension of file with given path.

Parameters
path String: Path to inspect.
Returns
String File extension in lower case.

public final String getGroupValue (String from, Pattern pattern, int groupIndex)

Finds given pattern in string and returns group by index.

Parameters
from String: String to inspect.
pattern Pattern: Pattern to find.
groupIndex int: Index of group.
Returns
String First found value in string by group index.

public String getPostNumber (Uri uri)

Returns post number from given URI. You must override this method.

Parameters
uri Uri: URI to inspect.
Returns
String Posts number.

public String getThreadNumber (Uri uri)

Returns thread number from given URI. You must override this method.

Parameters
uri Uri: URI to inspect.
Returns
String Thread number.

public ChanLocator.NavigationData handleUriClickSpecial (Uri uri)

Calls when client intend to handle link click. You can return ChanLocator.NavigationData instance with necessary navigation information.

Parameters
uri Uri: URI to inspect.
Returns
ChanLocator.NavigationData ChanLocator.NavigationData instance or null.

public boolean isAttachmentUri (Uri uri)

Returns whether URI is attachment URI. You must override this method.

Parameters
uri Uri: URI to inspect.
Returns
boolean True if URI is attachment URI.

public final boolean isAudioExtension (String path)

Returns whether path has audio extension.

Parameters
path String: Path to inspect.
Returns
boolean True if extension is audio's.

public boolean isBoardUri (Uri uri)

Returns whether URI is board URI. You must override this method.

Parameters
uri Uri: URI to inspect.
Returns
boolean True if URI is board URI.

public final boolean isChanHostOrRelative (Uri uri)

Returns whether URI's host is chan host or URI is relative (URI without scheme and host). This method will return true for all URI's with hosts declared with addChanHost(String) or addSpecialChanHost(String) methods and all relative URIs.

Parameters
uri Uri
Returns
boolean True if host is chan host or relative.

public final boolean isImageExtension (String path)

Returns whether path has image extension.

Parameters
path String: Path to inspect.
Returns
boolean True if extension is image's.

public final boolean isPathMatches (Uri uri, Pattern pattern)

Returns whether URI's path matches to given pattern.

Parameters
uri Uri: URI to inspect.
pattern Pattern: Pattern to match.
Returns
boolean True if URI's path matches to pattern.

public boolean isThreadUri (Uri uri)

Returns whether URI is thread URI. You must override this method.

Parameters
uri Uri: URI to inspect.
Returns
boolean True if URI is thread URI.

public final boolean isUseHttps ()

Returns whether HTTPS enabled in preferences.

Returns
boolean True if HTTPS enabled.

public final boolean isVideoExtension (String path)

Returns whether path has video extension.

Parameters
path String: Path to inspect.
Returns
boolean True if extension is video's.

public final void setHttpsMode (ChanLocator.HttpsMode httpsMode)

Changes default HTTPS mode. By default it equals NO_HTTPS.

Parameters
httpsMode ChanLocator.HttpsMode