Package com.atlassian.jira.jql.util
Class JqlStringSupportImpl
java.lang.Object
com.atlassian.jira.jql.util.JqlStringSupportImpl
- All Implemented Interfaces:
JqlStringSupport
Some utility code to help with JQL strings.
The JQL grammar depends on the implementation isReservedString(java.lang.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.
- Since:
- v4.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Remove escaping JQL escaping from the passed string.static String
encodeAsQuotedString
(String string) Encode the passed string into a valid JQL encoded quoted string.static String
encodeAsQuotedString
(String string, boolean escapeNewline) 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.encodeFieldName
(String fieldName) Encode the passed string into a safe JQL field name.encodeFunctionArgument
(String argument) Encode the passed string into a safe JQL function argument.encodeFunctionName
(String functionName) Encode the passed string into a safe JQL function name.encodeStringValue
(String value) Encode the passed string value into a safe JQL value if necessary.encodeValue
(String value) Encode the passed string value into a safe JQL value if necessary.generateJqlString
(Clause clause) Generates a JQL string representation for the passed clause.generateJqlString
(Query query) Generates a JQL string representation for the passed query.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.
-
Field Details
-
RESERVED_WORDS
-
-
Constructor Details
-
JqlStringSupportImpl
-
-
Method Details
-
getJqlReservedWords
- Specified by:
getJqlReservedWords
in interfaceJqlStringSupport
- Returns:
- all the reserved words for the JQL language.
-
encodeStringValue
Description copied from interface:JqlStringSupport
Encode the passed string value into a safe JQL value if necessary. The value will not be encoded if it is already safe.- Specified by:
encodeStringValue
in interfaceJqlStringSupport
- Parameters:
value
- the value to encode.- Returns:
- the encoded string.
-
encodeValue
Description copied from interface:JqlStringSupport
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 toJqlStringSupport.encodeStringValue(String)
since it will not add quotes around long values.- Specified by:
encodeValue
in interfaceJqlStringSupport
- Parameters:
value
- the value to encode.- Returns:
- the encoded string.
-
encodeFunctionArgument
Description copied from interface:JqlStringSupport
Encode the passed string into a safe JQL function argument. The value will not be encoded if it is already safe.- Specified by:
encodeFunctionArgument
in interfaceJqlStringSupport
- Parameters:
argument
- the string to encode.- Returns:
- the encoded string.
-
encodeFunctionName
Description copied from interface:JqlStringSupport
Encode the passed string into a safe JQL function name. This value will not be encoded if it is already safe.- Specified by:
encodeFunctionName
in interfaceJqlStringSupport
- Parameters:
functionName
- the string to encode.- Returns:
- the encoded string.
-
encodeFieldName
Description copied from interface:JqlStringSupport
Encode the passed string into a safe JQL field name. This value will not be encoded if it is already safe.- Specified by:
encodeFieldName
in interfaceJqlStringSupport
- Parameters:
fieldName
- the string to encode.- Returns:
- the encoded string.
-
generateJqlString
Description copied from interface:JqlStringSupport
Generates a JQL string representation for the passed query. The JQL string is always generated, that is,Query.getQueryString()
is completely ignored if it exists. The returned JQL is automatically escaped as necessary.- Specified by:
generateJqlString
in interfaceJqlStringSupport
- Parameters:
query
- the query. Cannot be null.- Returns:
- the generated JQL string representation of the passed query.
-
generateJqlString
Description copied from interface:JqlStringSupport
Generates a JQL string representation for the passed clause. The returned JQL is automatically escaped as necessary.- Specified by:
generateJqlString
in interfaceJqlStringSupport
- Parameters:
clause
- the clause. Cannot be null.- Returns:
- the generated JQL string representation of the passed clause.
-
decode
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.
-
encodeAsQuotedString
Encode the passed string into a valid JQL encoded quoted string.- Parameters:
string
- the string to encode.- Returns:
- the encoded string.
-
encodeAsQuotedString
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.
-
encodeCharacterForce
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.
-
encodeCharacter
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.
-
isReservedString
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.
-
isJqlControl
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.
-