|
@@ -4,6 +4,7 @@ import com.google.gson.JsonElement;
|
|
|
import com.google.gson.JsonObject;
|
|
import com.google.gson.JsonObject;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
|
|
+import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -12,12 +13,15 @@ import java.util.List;
|
|
|
public class InvalidFilesException extends SnapshotPostException {
|
|
public class InvalidFilesException extends SnapshotPostException {
|
|
|
|
|
|
|
|
private static final String[] DESCRIPTION_LINES = {
|
|
private static final String[] DESCRIPTION_LINES = {
|
|
|
- "You have invalid files in your WriteLatex project.",
|
|
|
|
|
- "Check your extensions."
|
|
|
|
|
|
|
+ "You have invalid files in your WriteLatex project."
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ private List<String> descriptionLines;
|
|
|
|
|
+
|
|
|
public InvalidFilesException(JsonObject json) {
|
|
public InvalidFilesException(JsonObject json) {
|
|
|
super(json);
|
|
super(json);
|
|
|
|
|
+ descriptionLines = new LinkedList<String>();
|
|
|
|
|
+ descriptionLines.addAll(Arrays.asList(DESCRIPTION_LINES));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -27,12 +31,39 @@ public class InvalidFilesException extends SnapshotPostException {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public List<String> getDescriptionLines() {
|
|
public List<String> getDescriptionLines() {
|
|
|
- return Arrays.asList(DESCRIPTION_LINES);
|
|
|
|
|
|
|
+ return descriptionLines;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void fromJSON(JsonElement json) {
|
|
public void fromJSON(JsonElement json) {
|
|
|
System.out.println(json);
|
|
System.out.println(json);
|
|
|
|
|
+ for (JsonElement error : json.getAsJsonObject().get("errors").getAsJsonArray()) {
|
|
|
|
|
+ descriptionLines.add(describeError(error.getAsJsonObject()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String describeError(JsonObject jsonObject) {
|
|
|
|
|
+ return jsonObject.get("file").getAsString() + " (" + describeFile(jsonObject) + ")";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String describeFile(JsonObject file) {
|
|
|
|
|
+ if (file.has("cleanFile")) {
|
|
|
|
|
+ return describeCleanFile(file.get("cleanFile").getAsString());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return describeErrorState(file.get("state").getAsString());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String describeCleanFile(String cleanFile) {
|
|
|
|
|
+ return "rename to: " + cleanFile;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String describeErrorState(String state) {
|
|
|
|
|
+ if (state.equals("disallowed")) {
|
|
|
|
|
+ return "invalid file extension";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return "error";
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|