Make sure all conditionals and loops are in blocks (too bug-prone otherwise)
git-svn-id: http://google-refine.googlecode.com/svn/trunk@2183 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
c16a2378f9
commit
da7347e7b1
@ -402,7 +402,9 @@ public class DataExtensionChange implements Change {
|
|||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
line = reader.readLine();
|
line = reader.readLine();
|
||||||
|
|
||||||
if (line == null) continue;
|
if (line == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (line.length() == 0) {
|
if (line.length() == 0) {
|
||||||
dataExtensions.add(null);
|
dataExtensions.add(null);
|
||||||
|
@ -162,12 +162,16 @@ public class RefineServlet extends Butterfly {
|
|||||||
Command command = commands.get(commandKey);
|
Command command = commands.get(commandKey);
|
||||||
if (command != null) {
|
if (command != null) {
|
||||||
if (request.getMethod().equals("GET")) {
|
if (request.getMethod().equals("GET")) {
|
||||||
if (!logger.isTraceEnabled()) logger.info("GET {}", request.getPathInfo());
|
if (!logger.isTraceEnabled()) {
|
||||||
|
logger.info("GET {}", request.getPathInfo());
|
||||||
|
}
|
||||||
logger.trace("> GET {}", commandKey);
|
logger.trace("> GET {}", commandKey);
|
||||||
command.doGet(request, response);
|
command.doGet(request, response);
|
||||||
logger.trace("< GET {}", commandKey);
|
logger.trace("< GET {}", commandKey);
|
||||||
} else if (request.getMethod().equals("POST")) {
|
} else if (request.getMethod().equals("POST")) {
|
||||||
if (!logger.isTraceEnabled()) logger.info("POST {}", request.getPathInfo());
|
if (!logger.isTraceEnabled()) {
|
||||||
|
logger.info("POST {}", request.getPathInfo());
|
||||||
|
}
|
||||||
logger.trace("> POST {}", commandKey);
|
logger.trace("> POST {}", commandKey);
|
||||||
command.doPost(request, response);
|
command.doPost(request, response);
|
||||||
logger.trace("< POST {}", commandKey);
|
logger.trace("< POST {}", commandKey);
|
||||||
|
@ -112,7 +112,9 @@ abstract public class TimeBinIndex {
|
|||||||
|
|
||||||
for (long step : steps) {
|
for (long step : steps) {
|
||||||
_step = step;
|
_step = step;
|
||||||
if (diff / _step <= 100) break;
|
if (diff / _step <= 100) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_bins = new int[(int) (diff / _step) + 1];
|
_bins = new int[(int) (diff / _step) + 1];
|
||||||
|
@ -96,7 +96,9 @@ public abstract class Command {
|
|||||||
*/
|
*/
|
||||||
static protected JSONObject getEngineConfig(HttpServletRequest request)
|
static protected JSONObject getEngineConfig(HttpServletRequest request)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
if (request == null) throw new IllegalArgumentException("parameter 'request' should not be null");
|
if (request == null) {
|
||||||
|
throw new IllegalArgumentException("parameter 'request' should not be null");
|
||||||
|
}
|
||||||
|
|
||||||
String json = request.getParameter("engine");
|
String json = request.getParameter("engine");
|
||||||
try{
|
try{
|
||||||
@ -118,13 +120,18 @@ public abstract class Command {
|
|||||||
*/
|
*/
|
||||||
static protected Engine getEngine(HttpServletRequest request, Project project)
|
static protected Engine getEngine(HttpServletRequest request, Project project)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
if (request == null) throw new IllegalArgumentException("parameter 'request' should not be null");
|
if (request == null) {
|
||||||
if (project == null) throw new IllegalArgumentException("parameter 'project' should not be null");
|
throw new IllegalArgumentException("parameter 'request' should not be null");
|
||||||
|
}
|
||||||
|
if (project == null) {
|
||||||
|
throw new IllegalArgumentException("parameter 'project' should not be null");
|
||||||
|
}
|
||||||
|
|
||||||
Engine engine = new Engine(project);
|
Engine engine = new Engine(project);
|
||||||
JSONObject o = getEngineConfig(request);
|
JSONObject o = getEngineConfig(request);
|
||||||
if (o != null)
|
if (o != null) {
|
||||||
engine.initializeFromJSON(o);
|
engine.initializeFromJSON(o);
|
||||||
|
}
|
||||||
return engine;
|
return engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +174,9 @@ public abstract class Command {
|
|||||||
* @throws ServletException
|
* @throws ServletException
|
||||||
*/
|
*/
|
||||||
protected ProjectMetadata getProjectMetadata(HttpServletRequest request) throws ServletException {
|
protected ProjectMetadata getProjectMetadata(HttpServletRequest request) throws ServletException {
|
||||||
if (request == null) throw new IllegalArgumentException("parameter 'request' should not be null");
|
if (request == null) {
|
||||||
|
throw new IllegalArgumentException("parameter 'request' should not be null");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
ProjectMetadata pm = ProjectManager.singleton.getProjectMetadata(Long.parseLong(request.getParameter("project")));
|
ProjectMetadata pm = ProjectManager.singleton.getProjectMetadata(Long.parseLong(request.getParameter("project")));
|
||||||
if (pm != null) {
|
if (pm != null) {
|
||||||
@ -180,7 +189,9 @@ public abstract class Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static protected int getIntegerParameter(HttpServletRequest request, String name, int def) {
|
static protected int getIntegerParameter(HttpServletRequest request, String name, int def) {
|
||||||
if (request == null) throw new IllegalArgumentException("parameter 'request' should not be null");
|
if (request == null) {
|
||||||
|
throw new IllegalArgumentException("parameter 'request' should not be null");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(request.getParameter(name));
|
return Integer.parseInt(request.getParameter(name));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -190,7 +201,9 @@ public abstract class Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static protected JSONObject getJsonParameter(HttpServletRequest request, String name) {
|
static protected JSONObject getJsonParameter(HttpServletRequest request, String name) {
|
||||||
if (request == null) throw new IllegalArgumentException("parameter 'request' should not be null");
|
if (request == null) {
|
||||||
|
throw new IllegalArgumentException("parameter 'request' should not be null");
|
||||||
|
}
|
||||||
String value = request.getParameter(name);
|
String value = request.getParameter(name);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -112,7 +112,9 @@ abstract public class HttpUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public int getIntegerParameter(HttpServletRequest request, String name, int def) {
|
static public int getIntegerParameter(HttpServletRequest request, String name, int def) {
|
||||||
if (request == null) throw new IllegalArgumentException("parameter 'request' should not be null");
|
if (request == null) {
|
||||||
|
throw new IllegalArgumentException("parameter 'request' should not be null");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(request.getParameter(name));
|
return Integer.parseInt(request.getParameter(name));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -122,7 +124,9 @@ abstract public class HttpUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public JSONObject getJsonParameter(HttpServletRequest request, String name) {
|
static public JSONObject getJsonParameter(HttpServletRequest request, String name) {
|
||||||
if (request == null) throw new IllegalArgumentException("parameter 'request' should not be null");
|
if (request == null) {
|
||||||
|
throw new IllegalArgumentException("parameter 'request' should not be null");
|
||||||
|
}
|
||||||
String value = request.getParameter(name);
|
String value = request.getParameter(name);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -22,12 +22,13 @@ public class ToggleStarredExpressionCommand extends Command {
|
|||||||
TopList starredExpressions = ((TopList) ProjectManager.singleton.getPreferenceStore().get(
|
TopList starredExpressions = ((TopList) ProjectManager.singleton.getPreferenceStore().get(
|
||||||
"scripting.starred-expressions"));
|
"scripting.starred-expressions"));
|
||||||
|
|
||||||
if (starredExpressions.getList().contains(expression))
|
if (starredExpressions.getList().contains(expression)) {
|
||||||
starredExpressions.remove(expression);
|
starredExpressions.remove(expression);
|
||||||
else
|
} else {
|
||||||
starredExpressions.add(expression);
|
starredExpressions.add(expression);
|
||||||
|
}
|
||||||
|
|
||||||
if(request.getParameter("returnList") != null)
|
if(request.getParameter("returnList") != null) {
|
||||||
try {
|
try {
|
||||||
response.setCharacterEncoding("UTF-8");
|
response.setCharacterEncoding("UTF-8");
|
||||||
response.setHeader("Content-Type", "application/json");
|
response.setHeader("Content-Type", "application/json");
|
||||||
@ -49,3 +50,4 @@ public class ToggleStarredExpressionCommand extends Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -47,8 +47,12 @@ public class CancelProcessesCommand extends Command {
|
|||||||
@Override
|
@Override
|
||||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
if( request == null ) throw new IllegalArgumentException("parameter 'request' should not be null");
|
if( request == null ) {
|
||||||
if( response == null ) throw new IllegalArgumentException("parameter 'request' should not be null");
|
throw new IllegalArgumentException("parameter 'request' should not be null");
|
||||||
|
}
|
||||||
|
if( response == null ) {
|
||||||
|
throw new IllegalArgumentException("parameter 'request' should not be null");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Project project = getProject(request);
|
Project project = getProject(request);
|
||||||
|
@ -46,21 +46,26 @@ public class Combin implements Function {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object call(Properties bindings, Object[] args) {
|
public Object call(Properties bindings, Object[] args) {
|
||||||
if(args.length != 2)
|
if(args.length != 2) {
|
||||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects two numbers");
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects two numbers");
|
||||||
if(args[0] == null || !(args[0] instanceof Number))
|
}
|
||||||
|
if(args[0] == null || !(args[0] instanceof Number)) {
|
||||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects the first argument to be a number");
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects the first argument to be a number");
|
||||||
if(args[1] == null || !(args[1] instanceof Number))
|
}
|
||||||
|
if(args[1] == null || !(args[1] instanceof Number)) {
|
||||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects the second argument to be a number");
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects the second argument to be a number");
|
||||||
|
}
|
||||||
|
|
||||||
return Combin.Combination(((Number) args[0]).intValue(), ((Number) args[1]).intValue());
|
return Combin.Combination(((Number) args[0]).intValue(), ((Number) args[1]).intValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int Combination(int n, int k){
|
public static int Combination(int n, int k){
|
||||||
if (k > n)
|
if (k > n) {
|
||||||
throw new IllegalArgumentException ("the number of elements, n, should be larger than the number of combinations, k");
|
throw new IllegalArgumentException ("the number of elements, n, should be larger than the number of combinations, k");
|
||||||
if (n < 1)
|
}
|
||||||
|
if (n < 1) {
|
||||||
throw new IllegalArgumentException ("the number of elements, n, cannot be less than 1");
|
throw new IllegalArgumentException ("the number of elements, n, cannot be less than 1");
|
||||||
|
}
|
||||||
int nFact = FactN.factorial(n, 1);
|
int nFact = FactN.factorial(n, 1);
|
||||||
int rFact = FactN.factorial(k, 1);
|
int rFact = FactN.factorial(k, 1);
|
||||||
int nminusrFact = FactN.factorial(n - k, 1);
|
int nminusrFact = FactN.factorial(n - k, 1);
|
||||||
|
@ -46,12 +46,15 @@ public class FactN implements Function {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object call(Properties bindings, Object[] args) {
|
public Object call(Properties bindings, Object[] args) {
|
||||||
if (args.length != 2)
|
if (args.length != 2) {
|
||||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects two numbers");
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects two numbers");
|
||||||
if(args[0] == null || !(args[0] instanceof Number))
|
}
|
||||||
|
if(args[0] == null || !(args[0] instanceof Number)) {
|
||||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects the first parameter to be a number");
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects the first parameter to be a number");
|
||||||
if(args[1] == null && !(args[1] instanceof Number))
|
}
|
||||||
|
if(args[1] == null && !(args[1] instanceof Number)) {
|
||||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects the second parameter to be a number");
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects the second parameter to be a number");
|
||||||
|
}
|
||||||
|
|
||||||
return FactN.factorial(((Number) args[0]).intValue(), ((Number) args[1]).intValue());
|
return FactN.factorial(((Number) args[0]).intValue(), ((Number) args[1]).intValue());
|
||||||
|
|
||||||
@ -63,11 +66,12 @@ public class FactN implements Function {
|
|||||||
* Returns 1 for zero and negative integers.
|
* Returns 1 for zero and negative integers.
|
||||||
*/
|
*/
|
||||||
public static int factorial(int i, int step){
|
public static int factorial(int i, int step){
|
||||||
if(i <= 1)
|
if(i <= 1) {
|
||||||
return 1;
|
return 1;
|
||||||
else
|
} else {
|
||||||
return i * FactN.factorial(i - step, step);
|
return i * FactN.factorial(i - step, step);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
|
@ -62,9 +62,10 @@ public class LeastCommonMultiple implements Function {
|
|||||||
smallerValue = a;
|
smallerValue = a;
|
||||||
}
|
}
|
||||||
for(int i = 1; i <= largerValue; i++){
|
for(int i = 1; i <= largerValue; i++){
|
||||||
if((largerValue*i) % smallerValue == 0)
|
if((largerValue*i) % smallerValue == 0) {
|
||||||
return largerValue * i;
|
return largerValue * i;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return largerValue * smallerValue;
|
return largerValue * smallerValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,13 +46,15 @@ public class Multinomial implements Function {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object call(Properties bindings, Object[] args) {
|
public Object call(Properties bindings, Object[] args) {
|
||||||
if (args.length < 1)
|
if (args.length < 1) {
|
||||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects one or more numbers");
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects one or more numbers");
|
||||||
|
}
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
int product = 1;
|
int product = 1;
|
||||||
for(int i = 0; i < args.length; i++){
|
for(int i = 0; i < args.length; i++){
|
||||||
if(args[i] == null && !(args[i] instanceof Number))
|
if(args[i] == null && !(args[i] instanceof Number)) {
|
||||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects parameter " + (i + 1) + " to be a number");
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects parameter " + (i + 1) + " to be a number");
|
||||||
|
}
|
||||||
int num = ((Number) args[i]).intValue();
|
int num = ((Number) args[i]).intValue();
|
||||||
sum += num;
|
sum += num;
|
||||||
product *= FactN.factorial(num, 1);
|
product *= FactN.factorial(num, 1);
|
||||||
|
@ -63,16 +63,30 @@ public class Diff implements Function {
|
|||||||
Date c1 = (o1 instanceof Date) ? (Date) o1 : ((Calendar) o1).getTime();
|
Date c1 = (o1 instanceof Date) ? (Date) o1 : ((Calendar) o1).getTime();
|
||||||
Date c2 = (o2 instanceof Date) ? (Date) o2 : CalendarParser.parse((o2 instanceof String) ? (String) o2 : o2.toString()).getTime();
|
Date c2 = (o2 instanceof Date) ? (Date) o2 : CalendarParser.parse((o2 instanceof String) ? (String) o2 : o2.toString()).getTime();
|
||||||
long delta = (c1.getTime() - c2.getTime()) / 1000;
|
long delta = (c1.getTime() - c2.getTime()) / 1000;
|
||||||
if ("seconds".equals(unit)) return delta;
|
if ("seconds".equals(unit)) {
|
||||||
|
return delta;
|
||||||
|
}
|
||||||
delta /= 60;
|
delta /= 60;
|
||||||
if ("minutes".equals(unit)) return delta;
|
if ("minutes".equals(unit)) {
|
||||||
|
return delta;
|
||||||
|
}
|
||||||
delta /= 60;
|
delta /= 60;
|
||||||
if ("hours".equals(unit)) return delta;
|
if ("hours".equals(unit)) {
|
||||||
|
return delta;
|
||||||
|
}
|
||||||
long days = delta / 24;
|
long days = delta / 24;
|
||||||
if ("days".equals(unit)) return days;
|
if ("days".equals(unit)) {
|
||||||
if ("weeks".equals(unit)) return days / 7;
|
return days;
|
||||||
if ("months".equals(unit)) return days / 30;
|
}
|
||||||
if ("years".equals(unit)) return days / 365;
|
if ("weeks".equals(unit)) {
|
||||||
|
return days / 7;
|
||||||
|
}
|
||||||
|
if ("months".equals(unit)) {
|
||||||
|
return days / 30;
|
||||||
|
}
|
||||||
|
if ("years".equals(unit)) {
|
||||||
|
return days / 365;
|
||||||
|
}
|
||||||
} catch (CalendarParserException e) {
|
} catch (CalendarParserException e) {
|
||||||
// we should throw at this point because it's important to know that date parsing failed
|
// we should throw at this point because it's important to know that date parsing failed
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,9 @@ public class Phonetic implements Function {
|
|||||||
if (o1 != null && o2 != null && o2 instanceof String) {
|
if (o1 != null && o2 != null && o2 instanceof String) {
|
||||||
String str = (o1 instanceof String) ? (String) o1 : o1.toString();
|
String str = (o1 instanceof String) ? (String) o1 : o1.toString();
|
||||||
String encoding = ((String) o2).toLowerCase();
|
String encoding = ((String) o2).toLowerCase();
|
||||||
if (encoding == null) encoding = "metaphone3";
|
if (encoding == null) {
|
||||||
|
encoding = "metaphone3";
|
||||||
|
}
|
||||||
if ("doublemetaphone".equalsIgnoreCase(encoding)) {
|
if ("doublemetaphone".equalsIgnoreCase(encoding)) {
|
||||||
return metaphone2.key(str);
|
return metaphone2.key(str);
|
||||||
} else if ("metaphone3".equalsIgnoreCase(encoding)) {
|
} else if ("metaphone3".equalsIgnoreCase(encoding)) {
|
||||||
|
@ -43,7 +43,9 @@ public class IsNumeric extends IsTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean test(Object o) {
|
protected boolean test(Object o) {
|
||||||
if (o instanceof Number) return true;
|
if (o instanceof Number) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
String s = (o instanceof String) ? (String) o : o.toString();
|
String s = (o instanceof String) ? (String) o : o.toString();
|
||||||
|
|
||||||
|
@ -79,7 +79,9 @@ public class ChangeSequence implements Change {
|
|||||||
|
|
||||||
static public Change load(LineNumberReader reader, Pool pool) throws Exception {
|
static public Change load(LineNumberReader reader, Pool pool) throws Exception {
|
||||||
String line = reader.readLine();
|
String line = reader.readLine();
|
||||||
if (line == null) line = "";
|
if (line == null) {
|
||||||
|
line = "";
|
||||||
|
}
|
||||||
int equal = line.indexOf('=');
|
int equal = line.indexOf('=');
|
||||||
|
|
||||||
assert "count".equals(line.substring(0, equal));
|
assert "count".equals(line.substring(0, equal));
|
||||||
|
@ -261,11 +261,12 @@ public class JsonImporter extends TreeImportingParserBase {
|
|||||||
|
|
||||||
//The following is a workaround for inconsistent Jackson JsonParser
|
//The following is a workaround for inconsistent Jackson JsonParser
|
||||||
if(text == null){
|
if(text == null){
|
||||||
if(this.lastTokenWasAFieldNameAndCurrentTokenIsANewEntity)
|
if(this.lastTokenWasAFieldNameAndCurrentTokenIsANewEntity) {
|
||||||
text = this.lastFieldName;
|
text = this.lastFieldName;
|
||||||
else
|
} else {
|
||||||
text = "__anonymous__";
|
text = "__anonymous__";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//end of workaround
|
//end of workaround
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
@ -307,8 +308,9 @@ public class JsonImporter extends TreeImportingParserBase {
|
|||||||
throw new ServletException(e);
|
throw new ServletException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(next == null)
|
if(next == null) {
|
||||||
throw new ServletException("No more Json Tokens in stream");
|
throw new ServletException("No more Json Tokens in stream");
|
||||||
|
}
|
||||||
|
|
||||||
//The following is a workaround for inconsistent Jackson JsonParser
|
//The following is a workaround for inconsistent Jackson JsonParser
|
||||||
if(next == JsonToken.FIELD_NAME){
|
if(next == JsonToken.FIELD_NAME){
|
||||||
|
@ -91,8 +91,9 @@ public class XmlImportUtilities extends TreeImportUtilities {
|
|||||||
*/
|
*/
|
||||||
static protected List<String> detectRecordElement(TreeReader parser, String tag) throws Exception {
|
static protected List<String> detectRecordElement(TreeReader parser, String tag) throws Exception {
|
||||||
try{
|
try{
|
||||||
if(parser.current() == Token.Ignorable)//XMLStreamConstants.START_DOCUMENT)
|
if(parser.current() == Token.Ignorable) {
|
||||||
parser.next();
|
parser.next();
|
||||||
|
}
|
||||||
|
|
||||||
String localName = parser.getFieldName();
|
String localName = parser.getFieldName();
|
||||||
String fullName = composeName(parser.getPrefix(), localName);
|
String fullName = composeName(parser.getPrefix(), localName);
|
||||||
@ -392,8 +393,9 @@ public class XmlImportUtilities extends TreeImportUtilities {
|
|||||||
) throws Exception {
|
) throws Exception {
|
||||||
logger.trace("processSubRecord(Project,TreeReader,ImportColumnGroup,ImportRecord)");
|
logger.trace("processSubRecord(Project,TreeReader,ImportColumnGroup,ImportRecord)");
|
||||||
|
|
||||||
if(parser.current() == Token.Ignorable)
|
if(parser.current() == Token.Ignorable) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ImportColumnGroup thisColumnGroup = getColumnGroup(
|
ImportColumnGroup thisColumnGroup = getColumnGroup(
|
||||||
project,
|
project,
|
||||||
|
@ -318,9 +318,15 @@ public class FileProjectManager extends ProjectManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void load() {
|
protected void load() {
|
||||||
if (loadFromFile(new File(_workspaceDir, "workspace.json"))) return;
|
if (loadFromFile(new File(_workspaceDir, "workspace.json"))) {
|
||||||
if (loadFromFile(new File(_workspaceDir, "workspace.temp.json"))) return;
|
return;
|
||||||
if (loadFromFile(new File(_workspaceDir, "workspace.old.json"))) return;
|
}
|
||||||
|
if (loadFromFile(new File(_workspaceDir, "workspace.temp.json"))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (loadFromFile(new File(_workspaceDir, "workspace.old.json"))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
logger.error("Failed to load workspace from any attempted alternatives.");
|
logger.error("Failed to load workspace from any attempted alternatives.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,12 +93,18 @@ public class IndentingLayout extends Layout {
|
|||||||
@Override
|
@Override
|
||||||
public String format(LoggingEvent event) {
|
public String format(LoggingEvent event) {
|
||||||
String message = event.getRenderedMessage();
|
String message = event.getRenderedMessage();
|
||||||
if (message == null) return "";
|
if (message == null) {
|
||||||
if (message.length() < 2) return message;
|
return "";
|
||||||
|
}
|
||||||
|
if (message.length() < 2) {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
char leader = message.charAt(0);
|
char leader = message.charAt(0);
|
||||||
char secondLeader = message.charAt(1);
|
char secondLeader = message.charAt(1);
|
||||||
if ((leader == '<') && (secondLeader == ' ') && (this.indentation > 0)) this.indentation--;
|
if ((leader == '<') && (secondLeader == ' ') && (this.indentation > 0)) {
|
||||||
|
this.indentation--;
|
||||||
|
}
|
||||||
|
|
||||||
// Reset buf
|
// Reset buf
|
||||||
StringBuffer buf = new StringBuffer(256);
|
StringBuffer buf = new StringBuffer(256);
|
||||||
@ -120,23 +126,33 @@ public class IndentingLayout extends Layout {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||||
if (hour < 10) buf.append('0');
|
if (hour < 10) {
|
||||||
|
buf.append('0');
|
||||||
|
}
|
||||||
buf.append(hour);
|
buf.append(hour);
|
||||||
buf.append(':');
|
buf.append(':');
|
||||||
|
|
||||||
int mins = calendar.get(Calendar.MINUTE);
|
int mins = calendar.get(Calendar.MINUTE);
|
||||||
if (mins < 10) buf.append('0');
|
if (mins < 10) {
|
||||||
|
buf.append('0');
|
||||||
|
}
|
||||||
buf.append(mins);
|
buf.append(mins);
|
||||||
buf.append(':');
|
buf.append(':');
|
||||||
|
|
||||||
int secs = calendar.get(Calendar.SECOND);
|
int secs = calendar.get(Calendar.SECOND);
|
||||||
if (secs < 10) buf.append('0');
|
if (secs < 10) {
|
||||||
|
buf.append('0');
|
||||||
|
}
|
||||||
buf.append(secs);
|
buf.append(secs);
|
||||||
buf.append('.');
|
buf.append('.');
|
||||||
|
|
||||||
int millis = (int) (now % 1000);
|
int millis = (int) (now % 1000);
|
||||||
if (millis < 100) buf.append('0');
|
if (millis < 100) {
|
||||||
if (millis < 10) buf.append('0');
|
buf.append('0');
|
||||||
|
}
|
||||||
|
if (millis < 10) {
|
||||||
|
buf.append('0');
|
||||||
|
}
|
||||||
buf.append(millis);
|
buf.append(millis);
|
||||||
|
|
||||||
buf.append(" [");
|
buf.append(" [");
|
||||||
@ -161,7 +177,9 @@ public class IndentingLayout extends Layout {
|
|||||||
buf.append(delta);
|
buf.append(delta);
|
||||||
buf.append("ms)\n");
|
buf.append("ms)\n");
|
||||||
|
|
||||||
if ((leader == '>') && (secondLeader == ' ')) indentation++;
|
if ((leader == '>') && (secondLeader == ' ')) {
|
||||||
|
indentation++;
|
||||||
|
}
|
||||||
|
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
@ -348,7 +348,9 @@ public class ColumnSplitChange implements Change {
|
|||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
line = reader.readLine();
|
line = reader.readLine();
|
||||||
|
|
||||||
if (line == null) continue;
|
if (line == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
int valueCount = Integer.parseInt(line);
|
int valueCount = Integer.parseInt(line);
|
||||||
|
|
||||||
|
@ -58,7 +58,9 @@ public class Credentials {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getCookieName(Provider provider) {
|
public String getCookieName(Provider provider) {
|
||||||
if (provider == null) throw new RuntimeException("Provider can't be null");
|
if (provider == null) {
|
||||||
|
throw new RuntimeException("Provider can't be null");
|
||||||
|
}
|
||||||
return provider.getHost() + "_" + postfix;
|
return provider.getHost() + "_" + postfix;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -89,11 +91,17 @@ public class Credentials {
|
|||||||
|
|
||||||
public Credentials(String token, String secret, Provider provider) {
|
public Credentials(String token, String secret, Provider provider) {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
if (token == null) throw new RuntimeException("Could not find " + TOKEN + " in auth credentials");
|
if (token == null) {
|
||||||
|
throw new RuntimeException("Could not find " + TOKEN + " in auth credentials");
|
||||||
|
}
|
||||||
this.secret = secret;
|
this.secret = secret;
|
||||||
if (secret == null) throw new RuntimeException("Could not find " + SECRET + " in auth credentials");
|
if (secret == null) {
|
||||||
|
throw new RuntimeException("Could not find " + SECRET + " in auth credentials");
|
||||||
|
}
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
if (provider == null) throw new RuntimeException("Provider can't be null");
|
if (provider == null) {
|
||||||
|
throw new RuntimeException("Provider can't be null");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getToken() {
|
public String getToken() {
|
||||||
|
@ -62,14 +62,20 @@ public class OAuthUtilities {
|
|||||||
int slash = path.lastIndexOf('/');
|
int slash = path.lastIndexOf('/');
|
||||||
String provider_str = path.substring(slash + 1);
|
String provider_str = path.substring(slash + 1);
|
||||||
Provider provider = getProvider(provider_str);
|
Provider provider = getProvider(provider_str);
|
||||||
if (provider == null) throw new RuntimeException("Can't find OAuth provider '" + provider_str + "'");
|
if (provider == null) {
|
||||||
|
throw new RuntimeException("Can't find OAuth provider '" + provider_str + "'");
|
||||||
|
}
|
||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OAuthConsumer getConsumer(Provider provider) {
|
public static OAuthConsumer getConsumer(Provider provider) {
|
||||||
if (provider == null) throw new RuntimeException("Provider can't be null");
|
if (provider == null) {
|
||||||
|
throw new RuntimeException("Provider can't be null");
|
||||||
|
}
|
||||||
String[] consumer_info = infos.get(provider.getHost());
|
String[] consumer_info = infos.get(provider.getHost());
|
||||||
if (consumer_info == null) throw new RuntimeException("Can't find secrets for provider '" + provider.getHost() + "'");
|
if (consumer_info == null) {
|
||||||
|
throw new RuntimeException("Can't find secrets for provider '" + provider.getHost() + "'");
|
||||||
|
}
|
||||||
OAuthConsumer oauthConsumer = provider.createConsumer(consumer_info[0],consumer_info[1]);
|
OAuthConsumer oauthConsumer = provider.createConsumer(consumer_info[0],consumer_info[1]);
|
||||||
HttpParameters params = new HttpParameters();
|
HttpParameters params = new HttpParameters();
|
||||||
params.put("realm", provider.getHost());
|
params.put("realm", provider.getHost());
|
||||||
|
@ -43,7 +43,9 @@ public class CookiesUtilities {
|
|||||||
public static final String PATH = "/";
|
public static final String PATH = "/";
|
||||||
|
|
||||||
public static Cookie getCookie(HttpServletRequest request, String name) {
|
public static Cookie getCookie(HttpServletRequest request, String name) {
|
||||||
if (name == null) throw new RuntimeException("cookie name cannot be null");
|
if (name == null) {
|
||||||
|
throw new RuntimeException("cookie name cannot be null");
|
||||||
|
}
|
||||||
Cookie cookie = null;
|
Cookie cookie = null;
|
||||||
Cookie[] cookies = request.getCookies();
|
Cookie[] cookies = request.getCookies();
|
||||||
if (cookies != null) {
|
if (cookies != null) {
|
||||||
@ -74,7 +76,9 @@ public class CookiesUtilities {
|
|||||||
|
|
||||||
public static String getDomain(HttpServletRequest request) {
|
public static String getDomain(HttpServletRequest request) {
|
||||||
String host = request.getHeader("Host");
|
String host = request.getHeader("Host");
|
||||||
if (host == null) return DOMAIN;
|
if (host == null) {
|
||||||
|
return DOMAIN;
|
||||||
|
}
|
||||||
int index = host.indexOf(':');
|
int index = host.indexOf(':');
|
||||||
return (index > -1) ? host.substring(0,index) : host ;
|
return (index > -1) ? host.substring(0,index) : host ;
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,9 @@ public class ParsingUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public JSONObject evaluateJsonStringToObject(String s) throws JSONException {
|
static public JSONObject evaluateJsonStringToObject(String s) throws JSONException {
|
||||||
if( s == null ) throw new IllegalArgumentException("parameter 's' should not be null");
|
if( s == null ) {
|
||||||
|
throw new IllegalArgumentException("parameter 's' should not be null");
|
||||||
|
}
|
||||||
JSONTokener t = new JSONTokener(s);
|
JSONTokener t = new JSONTokener(s);
|
||||||
Object o = t.nextValue();
|
Object o = t.nextValue();
|
||||||
if (o instanceof JSONObject) {
|
if (o instanceof JSONObject) {
|
||||||
|
@ -131,8 +131,9 @@ public class ImporterUtilitiesTests extends RefineTest {
|
|||||||
@Test
|
@Test
|
||||||
public void ensureColumnsInRowExistDoesExpand(){
|
public void ensureColumnsInRowExistDoesExpand(){
|
||||||
Row row = new Row(4);
|
Row row = new Row(4);
|
||||||
for(int i = 1; i < 5; i++)
|
for(int i = 1; i < 5; i++) {
|
||||||
row.cells.add(new Cell("value" + i, null));
|
row.cells.add(new Cell("value" + i, null));
|
||||||
|
}
|
||||||
|
|
||||||
ArrayList<String> columnNames = new ArrayList<String>(2);
|
ArrayList<String> columnNames = new ArrayList<String>(2);
|
||||||
|
|
||||||
|
@ -186,8 +186,9 @@ public class JsonImporterTests extends ImporterTest {
|
|||||||
try{
|
try{
|
||||||
while(token != null){
|
while(token != null){
|
||||||
token = parser.next();
|
token = parser.next();
|
||||||
if(token == null)
|
if(token == null) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
if(i == 3){
|
if(i == 3){
|
||||||
Assert.assertEquals(Token.Value, token);
|
Assert.assertEquals(Token.Value, token);
|
||||||
@ -205,8 +206,9 @@ public class JsonImporterTests extends ImporterTest {
|
|||||||
try{
|
try{
|
||||||
while(token != null){
|
while(token != null){
|
||||||
token = parser.next();
|
token = parser.next();
|
||||||
if(token == null)
|
if(token == null) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
if(i == 3){
|
if(i == 3){
|
||||||
Assert.assertEquals(Token.StartEntity, token);
|
Assert.assertEquals(Token.StartEntity, token);
|
||||||
@ -223,8 +225,9 @@ public class JsonImporterTests extends ImporterTest {
|
|||||||
try{
|
try{
|
||||||
while(token != null){
|
while(token != null){
|
||||||
token = parser.next();
|
token = parser.next();
|
||||||
if(token == null)
|
if(token == null) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
if(i == 3){
|
if(i == 3){
|
||||||
Assert.assertEquals(token, Token.StartEntity);
|
Assert.assertEquals(token, Token.StartEntity);
|
||||||
|
@ -93,8 +93,9 @@ public class XmlImportUtilitiesTests extends RefineTest {
|
|||||||
parser = null;
|
parser = null;
|
||||||
columnGroup = null;
|
columnGroup = null;
|
||||||
record = null;
|
record = null;
|
||||||
if(inputStream != null)
|
if(inputStream != null) {
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
|
}
|
||||||
inputStream = null;
|
inputStream = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,9 @@ class RefineServer extends Server {
|
|||||||
logger.info("Starting Server bound to '" + host + ":" + port + "'");
|
logger.info("Starting Server bound to '" + host + ":" + port + "'");
|
||||||
|
|
||||||
String memory = Configurations.get("refine.memory");
|
String memory = Configurations.get("refine.memory");
|
||||||
if (memory != null) logger.info("Max memory size: " + memory);
|
if (memory != null) {
|
||||||
|
logger.info("Max memory size: " + memory);
|
||||||
|
}
|
||||||
|
|
||||||
int maxThreads = Configurations.getInteger("refine.queue.size", 30);
|
int maxThreads = Configurations.getInteger("refine.queue.size", 30);
|
||||||
int maxQueue = Configurations.getInteger("refine.queue.max_size", 300);
|
int maxQueue = Configurations.getInteger("refine.queue.max_size", 300);
|
||||||
@ -200,7 +202,9 @@ class RefineServer extends Server {
|
|||||||
protected void doStop() throws Exception {
|
protected void doStop() throws Exception {
|
||||||
try {
|
try {
|
||||||
// shutdown our scheduled tasks first, if any
|
// shutdown our scheduled tasks first, if any
|
||||||
if (threadPool != null) threadPool.shutdown();
|
if (threadPool != null) {
|
||||||
|
threadPool.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
// then let the parent stop
|
// then let the parent stop
|
||||||
super.doStop();
|
super.doStop();
|
||||||
@ -210,8 +214,12 @@ class RefineServer extends Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static private boolean isWebapp(File dir) {
|
static private boolean isWebapp(File dir) {
|
||||||
if (dir == null) return false;
|
if (dir == null) {
|
||||||
if (!dir.exists() || !dir.canRead()) return false;
|
return false;
|
||||||
|
}
|
||||||
|
if (!dir.exists() || !dir.canRead()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
File webXml = new File(dir, "WEB-INF/web.xml");
|
File webXml = new File(dir, "WEB-INF/web.xml");
|
||||||
return webXml.exists() && webXml.canRead();
|
return webXml.exists() && webXml.canRead();
|
||||||
}
|
}
|
||||||
|
@ -60,12 +60,18 @@ public class IndentingLayout extends Layout {
|
|||||||
@Override
|
@Override
|
||||||
public String format(LoggingEvent event) {
|
public String format(LoggingEvent event) {
|
||||||
String message = event.getRenderedMessage();
|
String message = event.getRenderedMessage();
|
||||||
if (message == null) return "";
|
if (message == null) {
|
||||||
if (message.length() < 2) return message;
|
return "";
|
||||||
|
}
|
||||||
|
if (message.length() < 2) {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
char leader = message.charAt(0);
|
char leader = message.charAt(0);
|
||||||
char secondLeader = message.charAt(1);
|
char secondLeader = message.charAt(1);
|
||||||
if ((leader == '<') && (secondLeader == ' ') && (this.indentation > 0)) this.indentation--;
|
if ((leader == '<') && (secondLeader == ' ') && (this.indentation > 0)) {
|
||||||
|
this.indentation--;
|
||||||
|
}
|
||||||
|
|
||||||
// Reset buf
|
// Reset buf
|
||||||
StringBuffer buf = new StringBuffer(256);
|
StringBuffer buf = new StringBuffer(256);
|
||||||
@ -87,23 +93,33 @@ public class IndentingLayout extends Layout {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||||
if (hour < 10) buf.append('0');
|
if (hour < 10) {
|
||||||
|
buf.append('0');
|
||||||
|
}
|
||||||
buf.append(hour);
|
buf.append(hour);
|
||||||
buf.append(':');
|
buf.append(':');
|
||||||
|
|
||||||
int mins = calendar.get(Calendar.MINUTE);
|
int mins = calendar.get(Calendar.MINUTE);
|
||||||
if (mins < 10) buf.append('0');
|
if (mins < 10) {
|
||||||
|
buf.append('0');
|
||||||
|
}
|
||||||
buf.append(mins);
|
buf.append(mins);
|
||||||
buf.append(':');
|
buf.append(':');
|
||||||
|
|
||||||
int secs = calendar.get(Calendar.SECOND);
|
int secs = calendar.get(Calendar.SECOND);
|
||||||
if (secs < 10) buf.append('0');
|
if (secs < 10) {
|
||||||
|
buf.append('0');
|
||||||
|
}
|
||||||
buf.append(secs);
|
buf.append(secs);
|
||||||
buf.append('.');
|
buf.append('.');
|
||||||
|
|
||||||
int millis = (int) (now % 1000);
|
int millis = (int) (now % 1000);
|
||||||
if (millis < 100) buf.append('0');
|
if (millis < 100) {
|
||||||
if (millis < 10) buf.append('0');
|
buf.append('0');
|
||||||
|
}
|
||||||
|
if (millis < 10) {
|
||||||
|
buf.append('0');
|
||||||
|
}
|
||||||
buf.append(millis);
|
buf.append(millis);
|
||||||
|
|
||||||
buf.append(" [");
|
buf.append(" [");
|
||||||
@ -128,7 +144,9 @@ public class IndentingLayout extends Layout {
|
|||||||
buf.append(delta);
|
buf.append(delta);
|
||||||
buf.append("ms)\n");
|
buf.append("ms)\n");
|
||||||
|
|
||||||
if ((leader == '>') && (secondLeader == ' ')) indentation++;
|
if ((leader == '>') && (secondLeader == ' ')) {
|
||||||
|
indentation++;
|
||||||
|
}
|
||||||
|
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user