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 StringRemove escaping JQL escaping from the passed string.static StringencodeAsQuotedString(String string) Encode the passed string into a valid JQL encoded quoted string.static StringencodeAsQuotedString(String string, boolean escapeNewline) Encode the passed string into a valid JQL encoded quoted string.static StringencodeCharacter(char character) Encode the passed character so that it may be used in JQL.static StringencodeCharacterForce(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 booleanisJqlControl(char c) Tells if caller if the passed character is considered a control character by JQL.static booleanisReservedString(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:
getJqlReservedWordsin interfaceJqlStringSupport- Returns:
- all the reserved words for the JQL language.
-
encodeStringValue
Description copied from interface:JqlStringSupportEncode the passed string value into a safe JQL value if necessary. The value will not be encoded if it is already safe.- Specified by:
encodeStringValuein interfaceJqlStringSupport- Parameters:
value- the value to encode.- Returns:
- the encoded string.
-
encodeValue
Description copied from interface:JqlStringSupportEncode 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:
encodeValuein interfaceJqlStringSupport- Parameters:
value- the value to encode.- Returns:
- the encoded string.
-
encodeFunctionArgument
Description copied from interface:JqlStringSupportEncode the passed string into a safe JQL function argument. The value will not be encoded if it is already safe.- Specified by:
encodeFunctionArgumentin interfaceJqlStringSupport- Parameters:
argument- the string to encode.- Returns:
- the encoded string.
-
encodeFunctionName
Description copied from interface:JqlStringSupportEncode the passed string into a safe JQL function name. This value will not be encoded if it is already safe.- Specified by:
encodeFunctionNamein interfaceJqlStringSupport- Parameters:
functionName- the string to encode.- Returns:
- the encoded string.
-
encodeFieldName
Description copied from interface:JqlStringSupportEncode the passed string into a safe JQL field name. This value will not be encoded if it is already safe.- Specified by:
encodeFieldNamein interfaceJqlStringSupport- Parameters:
fieldName- the string to encode.- Returns:
- the encoded string.
-
generateJqlString
Description copied from interface:JqlStringSupportGenerates 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:
generateJqlStringin interfaceJqlStringSupport- Parameters:
query- the query. Cannot be null.- Returns:
- the generated JQL string representation of the passed query.
-
generateJqlString
Description copied from interface:JqlStringSupportGenerates a JQL string representation for the passed clause. The returned JQL is automatically escaped as necessary.- Specified by:
generateJqlStringin 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.
-