com.atlassian.jira.jql.util
Class JqlStringSupportImpl

java.lang.Object
  extended by com.atlassian.jira.jql.util.JqlStringSupportImpl
All Implemented Interfaces:
JqlStringSupport

public final class JqlStringSupportImpl
extends Object
implements 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
static Set<String> RESERVED_WORDS
           
 
Constructor Summary
JqlStringSupportImpl(JqlQueryParser parser)
           
 
Method Summary
static String decode(String 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.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESERVED_WORDS

public static final Set<String> RESERVED_WORDS
Constructor Detail

JqlStringSupportImpl

public JqlStringSupportImpl(JqlQueryParser parser)
Method Detail

getJqlReservedWords

public Set<String> getJqlReservedWords()
Specified by:
getJqlReservedWords in interface JqlStringSupport
Returns:
all the reserved words for the JQL language.

encodeStringValue

public String encodeStringValue(String value)
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 interface JqlStringSupport
Parameters:
value - the value to encode.
Returns:
the encoded string.

encodeValue

public String encodeValue(String value)
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 to JqlStringSupport.encodeStringValue(String) since it will not add quotes around long values.

Specified by:
encodeValue in interface JqlStringSupport
Parameters:
value - the value to encode.
Returns:
the encoded string.

encodeFunctionArgument

public String encodeFunctionArgument(String argument)
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 interface JqlStringSupport
Parameters:
argument - the string to encode.
Returns:
the encoded string.

encodeFunctionName

public String encodeFunctionName(String functionName)
Description copied from interface: JqlStringSupport
Encode the passed string into a safe JQL function name. This value will not be encoded if it is not already safe.

Specified by:
encodeFunctionName in interface JqlStringSupport
Parameters:
functionName - the string to encode.
Returns:
the encoded string.

encodeFieldName

public String encodeFieldName(String fieldName)
Description copied from interface: JqlStringSupport
Encode the passed string into a safe JQL field name. This value will not be encoded if it is not already safe.

Specified by:
encodeFieldName in interface JqlStringSupport
Parameters:
fieldName - the string to encode.
Returns:
the encoded string.

generateJqlString

public String generateJqlString(Query query)
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 interface JqlStringSupport
Parameters:
query - the query. Cannot be null.
Returns:
the generated JQL string representation of the passed query.

generateJqlString

public String generateJqlString(Clause clause)
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 interface JqlStringSupport
Parameters:
clause - the clause. Cannot be null.
Returns:
the generated JQL string representation of the passed clause.

decode

public static String decode(String string)
                     throws IllegalArgumentException
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

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.

encodeAsQuotedString

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.

encodeCharacterForce

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.

encodeCharacter

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.

isReservedString

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.

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.


Copyright © 2002-2012 Atlassian. All Rights Reserved.