-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,997 additions
and
2,102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/com/nccgroup/loggerplusplus/filter/ColorizingFilterRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.nccgroup.loggerplusplus.filter; | ||
|
||
import com.google.gson.annotations.JsonAdapter; | ||
import com.nccgroup.loggerplusplus.filter.colorfilter.TableColorRule; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.awt.*; | ||
|
||
public abstract class ColorizingFilterRule extends FilterRule { | ||
|
||
@Getter @Setter | ||
private Color backgroundColor; | ||
@Getter @Setter | ||
private Color foregroundColor; | ||
@Getter @Setter | ||
private short priority; | ||
@Getter @Setter | ||
private boolean enabled; | ||
|
||
protected ColorizingFilterRule(String name){ | ||
super(name); | ||
} | ||
|
||
protected ColorizingFilterRule(String name, FilterExpression filterExpression){ | ||
super(name, filterExpression); | ||
} | ||
|
||
protected ColorizingFilterRule(String name, String filter){ | ||
super(name, filter); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if(obj instanceof ColorizingFilterRule){ | ||
return ((TableColorRule) obj).getUuid().equals(this.getUuid()); | ||
}else{ | ||
return super.equals(obj); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/nccgroup/loggerplusplus/filter/FilterExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.nccgroup.loggerplusplus.filter; | ||
|
||
import com.nccgroup.loggerplusplus.LoggerPlusPlus; | ||
import com.nccgroup.loggerplusplus.filter.parser.*; | ||
import com.nccgroup.loggerplusplus.logentry.LogEntry; | ||
import com.nccgroup.loggerplusplus.logentry.LogEntryField; | ||
import lombok.Getter; | ||
|
||
import java.util.HashSet; | ||
|
||
public class FilterExpression { | ||
|
||
@Getter | ||
protected ASTExpression ast; | ||
|
||
@Getter | ||
protected HashSet<String> snippetDependencies; | ||
|
||
public FilterExpression(String filterString) throws ParseException { | ||
this.ast = FilterParser.parseFilter(filterString); | ||
this.snippetDependencies = FilterParser.checkAliasesForSanity(LoggerPlusPlus.instance.getLibraryController(), this.ast); | ||
} | ||
|
||
public boolean matches(LogEntry entry){ | ||
FilterEvaluationVisitor visitor = new FilterEvaluationVisitor(LoggerPlusPlus.instance.getLibraryController()); | ||
return visitor.visit(ast, entry); | ||
} | ||
|
||
public void addConditionToFilter(LogicalOperator logicalOperator, LogEntryField field, | ||
ComparisonOperator booleanOperator, String value) throws ParseException { | ||
String existing; | ||
if (this.ast.getLogicalOperator() != null && !this.ast.getLogicalOperator().equals(logicalOperator)) { | ||
existing = "(" + this.ast.getFilterString() + ")"; | ||
} else { | ||
existing = this.ast.getFilterString(); | ||
} | ||
|
||
this.ast = FilterParser.parseFilter(String.format("%s %s %s %s %s", existing, logicalOperator.toString(), field.toString(), booleanOperator, value)); | ||
this.snippetDependencies = FilterParser.checkAliasesForSanity(LoggerPlusPlus.instance.getLibraryController(), this.ast); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ast.getFilterString(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/nccgroup/loggerplusplus/filter/FilterExpressionSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.nccgroup.loggerplusplus.filter; | ||
|
||
import com.google.gson.*; | ||
import com.nccgroup.loggerplusplus.filter.parser.ParseException; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
public class FilterExpressionSerializer implements JsonSerializer<FilterExpression>, JsonDeserializer<FilterExpression> { | ||
|
||
@Override | ||
public JsonElement serialize(FilterExpression filter, Type type, JsonSerializationContext jsonSerializationContext) { | ||
JsonObject object = new JsonObject(); | ||
object.addProperty("filter", filter.toString()); | ||
return object; | ||
} | ||
|
||
@Override | ||
public FilterExpression deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { | ||
FilterExpression filter = null; | ||
try { | ||
filter = new FilterExpression(jsonElement.getAsJsonObject().get("filter").getAsString()); | ||
} catch (ParseException e) { | ||
} | ||
return filter; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/com/nccgroup/loggerplusplus/filter/FilterRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.nccgroup.loggerplusplus.filter; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import com.nccgroup.loggerplusplus.filter.parser.ParseException; | ||
import lombok.Getter; | ||
|
||
import java.util.UUID; | ||
|
||
public abstract class FilterRule { | ||
|
||
@Getter @SerializedName("uid") | ||
private UUID uuid; | ||
@Getter | ||
private String name; | ||
@Getter | ||
private String filterString; | ||
@Getter @SerializedName("filter") | ||
private FilterExpression filterExpression; | ||
|
||
public FilterRule(String name){ | ||
this.name = name; | ||
this.uuid = UUID.randomUUID(); | ||
} | ||
|
||
public FilterRule(String name, FilterExpression filterExpression){ | ||
this(name); | ||
this.filterExpression = filterExpression; | ||
this.filterString = filterExpression.toString(); | ||
} | ||
|
||
public FilterRule(String name, String filterString){ | ||
this(name); | ||
trySetFilter(filterString); | ||
} | ||
|
||
protected void setUuid(UUID uuid) { | ||
this.uuid = uuid; | ||
} | ||
|
||
public void setFilter(FilterExpression expression) { | ||
this.filterExpression = expression; | ||
if(expression != null) this.filterString = expression.toString(); | ||
} | ||
|
||
public void setName(String name){ | ||
this.name = name; | ||
} | ||
|
||
public boolean trySetFilter(String filterString){ | ||
this.filterString = filterString; | ||
try{ | ||
parseAndSetFilter(filterString); | ||
}catch (ParseException e){ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public void parseAndSetFilter(String filterString) throws ParseException { | ||
this.filterString = filterString; | ||
this.filterExpression = new FilterExpression(filterString); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/nccgroup/loggerplusplus/filter/SavedFilterSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.nccgroup.loggerplusplus.filter; | ||
|
||
import com.google.gson.*; | ||
import com.nccgroup.loggerplusplus.filter.savedfilter.SavedFilter; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.UUID; | ||
|
||
public class SavedFilterSerializer implements JsonSerializer<SavedFilter>, JsonDeserializer<SavedFilter> { | ||
|
||
@Override | ||
public JsonElement serialize(SavedFilter tag, Type type, JsonSerializationContext context) { | ||
JsonObject object = new JsonObject(); | ||
object.addProperty("uid", tag.getUuid().toString()); | ||
object.addProperty("name", tag.getName()); | ||
object.add("filter", context.serialize(tag.getFilterExpression())); | ||
return object; | ||
} | ||
|
||
@Override | ||
public SavedFilter deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { | ||
JsonObject obj = jsonElement.getAsJsonObject(); | ||
String uid = obj.get("uid").getAsString(); | ||
String name = obj.get("name").getAsString(); | ||
FilterExpression filterExpression = context.deserialize(obj.get("filter"), FilterExpression.class); | ||
|
||
SavedFilter tag = new SavedFilter(name, filterExpression); | ||
tag.setUuid(UUID.fromString(uid)); | ||
return tag; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/nccgroup/loggerplusplus/filter/TableColorRuleSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.nccgroup.loggerplusplus.filter; | ||
|
||
import com.google.gson.*; | ||
import com.nccgroup.loggerplusplus.filter.colorfilter.TableColorRule; | ||
|
||
import java.awt.*; | ||
import java.lang.reflect.Type; | ||
import java.util.UUID; | ||
|
||
public class TableColorRuleSerializer implements JsonSerializer<TableColorRule>, JsonDeserializer<TableColorRule> { | ||
|
||
@Override | ||
public JsonElement serialize(TableColorRule tag, Type type, JsonSerializationContext context) { | ||
JsonObject object = new JsonObject(); | ||
object.addProperty("uid", tag.getUuid().toString()); | ||
object.addProperty("name", tag.getName()); | ||
object.add("filter", context.serialize(tag.getFilterExpression())); | ||
object.add("foregroundColor", context.serialize(tag.getForegroundColor())); | ||
object.add("backgroundColor", context.serialize(tag.getBackgroundColor())); | ||
object.addProperty("enabled", tag.isEnabled()); | ||
object.addProperty("priority", tag.getPriority()); | ||
return object; | ||
} | ||
|
||
@Override | ||
public TableColorRule deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { | ||
JsonObject obj = jsonElement.getAsJsonObject(); | ||
String uid = obj.get("uid").getAsString(); | ||
String name = obj.has("name") ? obj.get("name").getAsString() : ""; | ||
FilterExpression filterExpression = context.deserialize(obj.get("filter"), FilterExpression.class); | ||
Color foregroundColor = context.deserialize(obj.get("foregroundColor"), Color.class); | ||
Color backgroundColor = context.deserialize(obj.get("backgroundColor"), Color.class); | ||
boolean enabled = obj.get("enabled").getAsBoolean(); | ||
short priority = obj.get("priority").getAsShort(); | ||
|
||
TableColorRule tag = new TableColorRule(name, filterExpression); | ||
tag.setUuid(UUID.fromString(uid)); | ||
tag.setForegroundColor(foregroundColor); | ||
tag.setBackgroundColor(backgroundColor); | ||
tag.setEnabled(enabled); | ||
tag.setPriority(priority); | ||
return tag; | ||
} | ||
} |
Oops, something went wrong.