URIList (class)

Categories:File

Overview

Summary

A utility class to load, cache and filter lists of URIs

Contents

Concept

The URIList is a utilty class to filter, sort and manipulate lists of URIs, and is mainly used in the xjsfl core for filtering searach paths, but can be used by any developer when they need to quickly filter or manage a URIs as a group.

Usage

For other methods of managing and filtering URIs also see:

API

URIList(source, recursive)

URIList constructor

Parameters:

  • source String A valid folder path or URI
  • source Array A list of URIs
  • recursive Boolean An optional flag to search the folder recursively

The following example grabs all the files and folders in and below the xJFSL user folder, by passing true as the second parameter:

var list = new URIList('//user/', true);
inspect(list.getPaths());		
Inspect: Array (depth:4, objects:0, values:72, time:0.0 seconds)
--------------------------------------------------------------------------------
array => Array
	 0: "E:/Projects/xJSFL/user/assets/"
	 1: "E:/Projects/xJSFL/user/assets/readme.txt"
	 2: "E:/Projects/xJSFL/user/assets/templates/"
	 3: "E:/Projects/xJSFL/user/assets/templates/as/"
	 4: "E:/Projects/xJSFL/user/assets/templates/as/class.as"
	 5: "E:/Projects/xJSFL/user/assets/templates/class.as"
	 6: "E:/Projects/xJSFL/user/assets/templates/jsfl/"
	 7: "E:/Projects/xJSFL/user/assets/templates/jsfl/snippet.jsfl"
	 8: "E:/Projects/xJSFL/user/config/"
	 9: "E:/Projects/xJSFL/user/config/readme.txt"
	 10: "E:/Projects/xJSFL/user/config/xjsfl.xml"
	 11: "E:/Projects/xJSFL/user/jsfl/"
	 12: "E:/Projects/xJSFL/user/jsfl/bootstrap.jsfl"
	 13: "E:/Projects/xJSFL/user/jsfl/libraries/"
	 14: "E:/Projects/xJSFL/user/jsfl/libraries/load-modules.jsfl"
	 15: "E:/Projects/xJSFL/user/jsfl/libraries/readme.txt"
	 16: "E:/Projects/xJSFL/user/jsfl/snippets/"
	 17: ....

Properties

length

Gets the number of URIs in the URIList

  • Type: Number
  • Access: Read

The following example returns the number of URIs in the current instance:

var list = new URIList('//user/');
trace(list.length);
6

Methods

getURIs(pattern, find)

Returns the list of URIs

Parameters:

  • pattern String A wildcard (*) pattern
  • pattern RegExp A regular expression
  • find Boolean An optional Boolean to return the first URI found

Returns:

  •   URI A single URI, if find is passed as true
  •   Array An Array of URI strings

The following example grabs all files from the user folder, but passes a string to getURIs to return only the URIs from the templates/ folder:

var list = new URIList('//user/', true);
var uris = list.getURIs('/templates/');
inspect(uris);
Inspect: Array (depth:4, objects:0, values:6, time:0.0 seconds)
--------------------------------------------------------------------------------
array => Array
	 0: "file:///E|/05%20-%20Commercial%20Projects/xJSFL/3%20-%20development/xJSFL/user/assets/templates/"
	 1: "file:///E|/05%20-%20Commercial%20Projects/xJSFL/3%20-%20development/xJSFL/user/assets/templates/as/"
	 2: "file:///E|/05%20-%20Commercial%20Projects/xJSFL/3%20-%20development/xJSFL/user/assets/templates/as/class.as"
	 3: "file:///E|/05%20-%20Commercial%20Projects/xJSFL/3%20-%20development/xJSFL/user/assets/templates/class.as"
	 4: "file:///E|/05%20-%20Commercial%20Projects/xJSFL/3%20-%20development/xJSFL/user/assets/templates/jsfl/"
	 5: "file:///E|/05%20-%20Commercial%20Projects/xJSFL/3%20-%20development/xJSFL/user/assets/templates/jsfl/snippet.jsfl"

The following example uses the wildcard string *.* to only grab the files from the templates/ folder:

var list = new URIList('//user/', true);
var uris = list.getURIs('/templates/*.*');
inspect(uris);
Inspect: Array (depth:4, objects:0, values:3, time:0.0 seconds)
--------------------------------------------------------------------------------
array => Array
	 0: "file:///E|/05%20-%20Commercial%20Projects/xJSFL/3%20-%20development/xJSFL/user/assets/templates/as/class.as"
	 1: "file:///E|/05%20-%20Commercial%20Projects/xJSFL/3%20-%20development/xJSFL/user/assets/templates/class.as"
	 2: "file:///E|/05%20-%20Commercial%20Projects/xJSFL/3%20-%20development/xJSFL/user/assets/templates/jsfl/snippet.jsfl"

getPaths(pattern, find)

Returns the list of Paths

Parameters:

  • pattern String A wildcard (*) pattern
  • pattern RegExp A regular expression
  • find Boolean An optional Boolean to return the first URI found

Returns:

  •   URI A single URI, if find is passed as true
  •   Array An Array of path strings

The following example is the same as above, but returns paths not URIs:

var list = new URIList('//user/', true);
var paths = list.getPaths('/templates/*.*');
inspect(paths);
array => Array
	 0: "E:/Projects/xJSFL/user/assets/templates/as/class.as"
	 1: "E:/Projects/xJSFL/user/assets/templates/class.as"
	 2: "E:/Projects/xJSFL/user/assets/templates/jsfl/snippet.jsfl"

filter(pattern)

Filters the URIs according to a wildcard pattern or regular expression

Parameters:

  • pattern String A wildcard (*) pattern
  • pattern RegExp A regular expression

Returns:

  •   Array An Array of URIs

The filter() method is the partner to find(), and is the function that is called directly by getURIs() and indirectly by getPaths().

See getURIs() for an example.

find(pattern)

Finds the first URI that matches a wildcard pattern or regular expression

Parameters:

  • pattern String A wildcard (*) pattern
  • pattern RegExp A regular expression

Returns:

  •   Array An Array of URIs

The find() method is the partner to filter(), and is the function that is called directly by getURIs() and indirectly by getPaths(), with the second parameter as true.

See getURIs() for an example.

append(source, recursive)

Appends new URIs onto the existing list of URIs

Parameters:

  • source String A valid folder path or URI
  • source Array A list of URIs
  • recursive Boolean An optional flag to search the folder recursively

Returns:

  •   URIList The original URIList instance

The following example creates a URI list from various directories and allows you to treat them as a group:

var list = new URIList('//user/jsfl/', true)
			.append('//core/jsfl/', true)
			.append('//modules/Snippets/jsfl/', true)
			.append('//modules/Sample Module/jsfl/', true);
trace(list);
[object URIList length=123]		

toString()

Returns a String representation of the URIList

Returns:

  •   String The String representation of the URIList

The following example :

var list = new URIList('//user/');
trace(list);
[object URIList length=6]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>