com.scooterframework.orm.activerecord.tag
Class TagHelper

java.lang.Object
  extended by com.scooterframework.orm.activerecord.tag.TagHelper

public class TagHelper
extends java.lang.Object

TagHelper has helper methods related to tags.


Constructor Summary
TagHelper()
           
 
Method Summary
static void addTags(java.lang.String tags)
          Adds tags to tags table.
static java.util.Set<java.lang.String> allTags()
          Returns all tag names.
static java.util.Set<java.lang.String> allTags(ActiveRecord record)
          Returns a set of tag names associated with a record instance.
static java.util.List<ActiveRecord> findOrCreateTagRecords(java.lang.String tags)
          Returns all tag records as specified by the tags.
static java.util.List<ActiveRecord> findRecordsTaggedWith(java.lang.String tags)
          Returns records tagged with tags.
static java.util.List<ActiveRecord> findRecordsTaggedWith(java.lang.String type, java.lang.String tags)
          Returns records of a certain type that are tagged with tags.
static java.util.List<ActiveRecord> findTagRecords(java.lang.String tags)
          Returns all tag records as specified by the tags.
static void registerTaggables(java.lang.Class<? extends ActiveRecord>[] targets)
          Registers record types that can be treated as taggable.
static void removeRecordTags(ActiveRecord record, java.lang.String tags)
          Removes all tag records as specified by the tags string for a record.
static void removeTags(java.lang.String tags)
          Removes all tag records as specified by the tags string.
static int tagsCount(ActiveRecord record)
          Returns a count of all tag names associated with a record instance.
static AssociatedRecords tagWith(ActiveRecord record, java.lang.String tags)
          Adds tags to a record.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TagHelper

public TagHelper()
Method Detail

allTags

public static java.util.Set<java.lang.String> allTags()
Returns all tag names.

Returns:
a set of tag names

addTags

public static void addTags(java.lang.String tags)
Adds tags to tags table. If a tag is already in the tags table, it is ignored.

Parameters:
tags - the tags string

registerTaggables

public static void registerTaggables(java.lang.Class<? extends ActiveRecord>[] targets)
Registers record types that can be treated as taggable. This methods must be called first before using other methods related to a target in TagHelper.

Parameters:
targets - specific types that act as taggable.

allTags

public static java.util.Set<java.lang.String> allTags(ActiveRecord record)
Returns a set of tag names associated with a record instance.

Parameters:
record -
Returns:
a set of tag names

tagsCount

public static int tagsCount(ActiveRecord record)
Returns a count of all tag names associated with a record instance.

Parameters:
record -
Returns:
number of tags associated with the record

tagWith

public static AssociatedRecords tagWith(ActiveRecord record,
                                        java.lang.String tags)
Adds tags to a record. Multiple tags can be listed in the same string separated by a delimiter. If a tag is not in the tag table, it will be added to the Tag table first. The delimiter string to separate tag names can be one of the three characters: "," or "|" or "&". String tag list string has the following format:
          java, j2ee, jdbc,...
       or java|j2ee|jdbc|...
       or java&j2ee&jdbc&...
 

Parameters:
record - the record to be tagged
tags - a string of tags separated by comma
Returns:
instance of AssociatedRecords

findTagRecords

public static java.util.List<ActiveRecord> findTagRecords(java.lang.String tags)
Returns all tag records as specified by the tags. If a tag is not in the tags table, it is ignored.

Parameters:
tags - the tags string
Returns:
list of tag records

findOrCreateTagRecords

public static java.util.List<ActiveRecord> findOrCreateTagRecords(java.lang.String tags)
Returns all tag records as specified by the tags. If a tag is not in the tags table, it is added to the table.

Parameters:
tags - the tags string
Returns:
list of tag records

findRecordsTaggedWith

public static java.util.List<ActiveRecord> findRecordsTaggedWith(java.lang.String tags)
Returns records tagged with tags.

Parameters:
tags - the tags condition
Returns:
records tagged with the tags.

findRecordsTaggedWith

public static java.util.List<ActiveRecord> findRecordsTaggedWith(java.lang.String type,
                                                                 java.lang.String tags)
Returns records of a certain type that are tagged with tags.

Parameters:
type - the specific record type
tags - the tags condition
Returns:
records tagged with the tags.

removeTags

public static void removeTags(java.lang.String tags)
Removes all tag records as specified by the tags string.

Parameters:
tags - the tags string

removeRecordTags

public static void removeRecordTags(ActiveRecord record,
                                    java.lang.String tags)
Removes all tag records as specified by the tags string for a record.

Parameters:
tags - the tags string