public final class

JqlStringSupportImpl

extends Object
implements JqlStringSupport
java.lang.Object
   ↳ com.atlassian.jira.jql.util.JqlStringSupportImpl

Class Overview

Some utility code to help with JQL strings.

The JQL grammar depends on the implementation isReservedString(String) method from this class. The other methods depend upon the definitions within the JQL grammar (Jql.g). Changing the grammar will likely require changing this class.

Summary

Fields
public static final Set<String> RESERVED_WORDS
Public Constructors
JqlStringSupportImpl(JqlQueryParser parser)
Public Methods
static String decode(String string)
Remove escaping JQL escaping from the passed string.
static String encodeAsQuotedString(String string, boolean escapeNewline)
Encode the passed string into a valid JQL encoded quoted string.
static String encodeAsQuotedString(String string)
Encode the passed string into a valid JQL encoded quoted string.
static String encodeCharacter(char character)
Encode the passed character so that it may be used in JQL.
static String encodeCharacterForce(char character)
Escape the passed character so that it may be used in JQL.
String encodeFieldName(String fieldName)
Encode the passed string into a safe JQL field name.
String encodeFunctionArgument(String argument)
Encode the passed string into a safe JQL function argument.
String encodeFunctionName(String functionName)
Encode the passed string into a safe JQL function name.
String encodeStringValue(String value)
Encode the passed string value into a safe JQL value if necessary.
String encodeValue(String value)
Encode the passed string value into a safe JQL value if necessary.
String generateJqlString(Clause clause)
Generates a JQL string representation for the passed clause.
String generateJqlString(Query query)
Generates a JQL string representation for the passed query.
Set<String> getJqlReservedWords()
static boolean isJqlControl(char c)
Tells if caller if the passed character is considered a control character by JQL.
static boolean isReservedString(String string)
Tell the caller if the passed string is a reserved JQL string.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.atlassian.jira.jql.util.JqlStringSupport

Fields

public static final Set<String> RESERVED_WORDS

Public Constructors

public JqlStringSupportImpl (JqlQueryParser parser)

Public Methods

public static String decode (String string)

Remove escaping JQL escaping from the passed string.

Parameters
string the string to decode.
Returns
  • the decoded string.
Throws
IllegalArgumentException if the input string contains invalid escape sequences.

public static String encodeAsQuotedString (String string, boolean escapeNewline)

Encode the passed string into a valid JQL encoded quoted string. A JQL string can represent newline (\n) and carriage return (\r) in two different ways: Its raw value or its escaped value. The passed boolean flag can be used to control which representation is used.

Parameters
string the string to encode.
escapeNewline should escape and newline characters be escaped.
Returns
  • the encoded string.

public static String encodeAsQuotedString (String string)

Encode the passed string into a valid JQL encoded quoted string.

Parameters
string the string to encode.
Returns
  • the encoded string.

public static String encodeCharacter (char character)

Encode the passed character so that it may be used in JQL. null will be returned if the character does not need to be encoded.

Parameters
character the character to encode.
Returns
  • the encoded character or null if it does not need to be encoded.

public static String encodeCharacterForce (char character)

Escape the passed character so that it may be used in JQL. The character is escaped even if it does not need to be.

Parameters
character the character to escape.
Returns
  • the escaped character.

public String encodeFieldName (String fieldName)

Encode the passed string into a safe JQL field name. This value will not be encoded if it is not already safe.

Parameters
fieldName the string to encode.
Returns
  • the encoded string.

public String encodeFunctionArgument (String argument)

Encode the passed string into a safe JQL function argument. The value will not be encoded if it is already safe.

Parameters
argument the string to encode.
Returns
  • the encoded string.

public String encodeFunctionName (String functionName)

Encode the passed string into a safe JQL function name. This value will not be encoded if it is not already safe.

Parameters
functionName the string to encode.
Returns
  • the encoded string.

public String encodeStringValue (String value)

Encode the passed string value into a safe JQL value if necessary. The value will not be encoded if it is already safe.

Parameters
value the value to encode.
Returns
  • the encoded string.

public String encodeValue (String value)

Encode the passed string value into a safe JQL value if necessary. The value will not be encoded if it is already safe. This is different to encodeStringValue(String) since it will not add quotes around long values.

Parameters
value the value to encode.
Returns
  • the encoded string.

public String generateJqlString (Clause clause)

Generates a JQL string representation for the passed clause. The returned JQL is automatically escaped as necessary.

Parameters
clause the clause. Cannot be null.
Returns
  • the generated JQL string representation of the passed clause.

public String generateJqlString (Query query)

Generates a JQL string representation for the passed query. The JQL string is always generated, that is, getQueryString() is completely ignored if it exists. The returned JQL is automatically escaped as necessary.

Parameters
query the query. Cannot be null.
Returns
  • the generated JQL string representation of the passed query.

public Set<String> getJqlReservedWords ()

public static boolean isJqlControl (char c)

Tells if caller if the passed character is considered a control character by JQL.

NOTE: This method duplicates some logic from the grammar. If the grammar changes then this method will also need to change. We have replicated the logic for effeciency reasons.

Parameters
c the character to check.
Returns
  • true if the passed character is a JQL control character, false otherwise.

public static boolean isReservedString (String string)

Tell the caller if the passed string is a reserved JQL string. We do this in here rather than the grammar because ANTLR does not deal well (generates a huge and very slow lexer) when matching lots of different tokens. In fact, the ANTLR grammar calls this method internally to see if a JQL string is reserved.

Parameters
string the word to test.
Returns
  • true if the passed string is a JQL reserved word.