Skip to content

Commit

Permalink
Updated for Fluenta 3.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed May 3, 2023
1 parent c5a8819 commit 44b05f8
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 22 deletions.
Binary file modified jars/openxliff.jar
Binary file not shown.
Binary file modified jars/swordfish.jar
Binary file not shown.
Binary file modified jars/xmljava.jar
Binary file not shown.
6 changes: 3 additions & 3 deletions src/com/maxprograms/fluenta/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static String getMemories() throws IOException, JSONException, ParseExcep
return result.toString(3);
}

protected static void addMemory(String jsonFile) throws IOException {
protected static void addMemory(String jsonFile) throws IOException, JSONException, ParseException {
File memoryFile = new File(jsonFile);
JSONObject jsonObject = FileUtils.readJSON(memoryFile);
long id = jsonObject.getLong("id");
Expand All @@ -133,7 +133,7 @@ protected static void addMemory(String jsonFile) throws IOException {
}

public static void addMemory(long id, String title, String description, String srcLang, String[] tgtLang)
throws IOException {
throws IOException, JSONException, ParseException {
Language srcLanguage = LanguageUtils.getLanguage(srcLang);
if (tgtLang == null || tgtLang.length == 0) {
throw new IOException("Missing target languages");
Expand Down Expand Up @@ -292,4 +292,4 @@ public static void removeProject(long id) throws IOException, JSONException, Par
}
controller.removeProject(project);
}
}
}
2 changes: 1 addition & 1 deletion src/com/maxprograms/fluenta/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static void main(String[] args) {
if (addMemory) {
try {
API.addMemory(addMemFile);
} catch (IOException e) {
} catch (IOException | JSONException | ParseException e) {
logger.log(Level.ERROR, "Error adding memory", e);
System.exit(3);
}
Expand Down
4 changes: 2 additions & 2 deletions src/com/maxprograms/fluenta/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ private Constants() {
}

public static final String NAME = "Fluenta";
public static final String VERSION = "3.6.0";
public static final String BUILD = "20230225_0751";
public static final String VERSION = "3.7.0";
public static final String BUILD = "20230503_0805";
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void createProject(Project project)
memoriesManager.add(memory);
}

public void createMemory(Memory memory) throws IOException {
public void createMemory(Memory memory) throws IOException, JSONException, ParseException {
if (memoriesManager == null) {
Preferences preferences = Preferences.getInstance();
memoriesManager = new MemoriesManager(preferences.getMemoriesFolder());
Expand Down
24 changes: 23 additions & 1 deletion src/com/maxprograms/fluenta/controllers/MemoriesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Vector;

Expand All @@ -32,17 +35,36 @@ public class MemoriesManager {
private File memoriesFile;
private JSONObject memories;

public MemoriesManager(File home) throws IOException, JSONException {
public MemoriesManager(File home) throws IOException, JSONException, ParseException {
if (!home.exists()) {
Files.createDirectories(home.toPath());
}
memoriesFile = new File(home, "memories.json");
if (!memoriesFile.exists()) {
memories = new JSONObject();
memories.put("version", Memory.VERSION);
memories.put("memories", new JSONArray());
saveMemories();
}
memories = FileUtils.readJSON(memoriesFile);
if (!memories.has("version") || memories.getInt("version") != Memory.VERSION) {
upgradeMemories();
saveMemories();
}
}

private void upgradeMemories() throws JSONException, ParseException {
DateFormat df = DateFormat.getDateTimeInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
JSONArray array = memories.getJSONArray("memories");
for (int i = 0; i < array.length(); i++) {
JSONObject memory = array.getJSONObject(i);
Date creationDate = df.parse(memory.getString("creationDate"));
memory.put("creationDate", sdf.format(creationDate));
Date lastUpdate = df.parse(memory.getString("lastUpdate"));
memory.put("lastUpdate", sdf.format(lastUpdate));
}
memories.put("version", Memory.VERSION);
}

private synchronized void saveMemories() throws IOException {
Expand Down
32 changes: 32 additions & 0 deletions src/com/maxprograms/fluenta/controllers/ProjectsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Vector;

Expand All @@ -39,17 +42,45 @@ public ProjectsManager(File home) throws IOException, JSONException, ParseExcept
projectsFile = new File(home, "projects.json");
if (!projectsFile.exists()) {
JSONObject json = new JSONObject();
json.put("version", Project.VERSION);
json.put("projects", new JSONArray());
try (FileOutputStream out = new FileOutputStream(projectsFile)) {
out.write(json.toString(2).getBytes(StandardCharsets.UTF_8));
}
}
projects = new Vector<>();
JSONObject json = FileUtils.readJSON(projectsFile);
if (!json.has("version") || json.getInt("version") != Project.VERSION) {
json = upgradeProjects(json);
}
JSONArray array = json.getJSONArray("projects");
for (int i = 0; i < array.length(); i++) {
projects.add(new Project(array.getJSONObject(i)));
}
if (!json.has("version") || json.getInt("version") != Project.VERSION) {
saveProjects();
}
}

private JSONObject upgradeProjects(JSONObject json) throws JSONException, ParseException {
JSONArray projects = json.getJSONArray("projects");
DateFormat df = DateFormat.getDateTimeInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
DateFormat ldf = DateFormat.getDateInstance(DateFormat.LONG);
for (int i = 0; i < projects.length(); i++) {
JSONObject project = projects.getJSONObject(i);
Date creationDate = df.parse(project.getString("creationDate"));
project.put("creationDate", sdf.format(creationDate));
Date lastUpdate = df.parse(project.getString("lastUpdate"));
project.put("lastUpdate", sdf.format(lastUpdate));
JSONArray history = project.getJSONArray("history");
for (int j = 0; j < history.length(); j++) {
JSONObject entry = history.getJSONObject(j);
Date date = ldf.parse(entry.getString("date"));
entry.put("date", sdf.format(date));
}
}
return json;
}

private synchronized void saveProjects() throws IOException {
Expand All @@ -59,6 +90,7 @@ private synchronized void saveProjects() throws IOException {
array.put(projects.get(i).toJSON());
}
json.put("projects", array);
json.put("version", Project.VERSION);
try (FileOutputStream out = new FileOutputStream(projectsFile)) {
out.write(json.toString(2).getBytes(StandardCharsets.UTF_8));
}
Expand Down
8 changes: 5 additions & 3 deletions src/com/maxprograms/fluenta/models/Memory.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import java.io.IOException;
import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Collections;
Expand All @@ -34,6 +34,8 @@ public class Memory implements Serializable {

private static final long serialVersionUID = -2993476438052822309L;

public static final int VERSION = 1;

private long id;
private String name;
private String description;
Expand All @@ -60,7 +62,7 @@ public Memory(JSONObject json) throws JSONException, ParseException, IOException
this.name = json.getString("name");
this.description = json.getString("description");
this.owner = json.getString("owner");
DateFormat df = DateFormat.getDateTimeInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
this.creationDate = df.parse(json.getString("creationDate"));
this.lastUpdate = df.parse(json.getString("lastUpdate"));
this.srcLanguage = LanguageUtils.getLanguage(json.getString("srcLanguage"));
Expand All @@ -73,7 +75,7 @@ public Memory(JSONObject json) throws JSONException, ParseException, IOException

public JSONObject toJSON() {
JSONObject json = new JSONObject();
DateFormat df = DateFormat.getDateTimeInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
json.put("id", id);
json.put("name", name);
json.put("description", description);
Expand Down
8 changes: 5 additions & 3 deletions src/com/maxprograms/fluenta/models/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.Hashtable;
Expand All @@ -40,6 +40,8 @@ public class Project implements Serializable {
public static final String COMPLETED = "Completed";
private static final String UNTRANSLATED = "Untranslated";

public static final int VERSION = 1;

private static final long serialVersionUID = 6996995538736280348L;

private long id;
Expand Down Expand Up @@ -91,7 +93,7 @@ public Project(JSONObject json) throws JSONException, ParseException, IOExceptio
if (!mapFile.isAbsolute()) {
map = Utils.getAbsolutePath(System.getProperty("user.home"), map);
}
DateFormat df = DateFormat.getDateTimeInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
creationDate = df.parse(json.getString("creationDate"));
status = json.getString("status");
lastUpdate = df.parse(json.getString("lastUpdate"));
Expand Down Expand Up @@ -128,7 +130,7 @@ public Project(JSONObject json) throws JSONException, ParseException, IOExceptio

public JSONObject toJSON() throws JSONException, IOException {
JSONObject json = new JSONObject();
DateFormat df = DateFormat.getDateTimeInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
json.put("id", id);
json.put("title", title);
json.put("description", description);
Expand Down
6 changes: 3 additions & 3 deletions src/com/maxprograms/fluenta/models/ProjectEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package com.maxprograms.fluenta.models;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
Expand Down Expand Up @@ -45,15 +45,15 @@ public ProjectEvent(String type, Date date, String language, int build) {

public ProjectEvent(JSONObject json) throws JSONException, ParseException {
this.type = json.getString("type");
this.date = DateFormat.getDateInstance(DateFormat.LONG).parse(json.getString("date"));
this.date = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(json.getString("date"));
this.language = json.getString("language");
this.build = json.getInt("build");
}

public JSONObject toJSON() {
JSONObject json = new JSONObject();
json.put("type", type);
json.put("date", DateFormat.getDateInstance(DateFormat.LONG).format(date));
json.put("date", new SimpleDateFormat("yyyy-MM-dd HH:mm").format(date));
json.put("language", language);
json.put("build", build);
return json;
Expand Down
8 changes: 6 additions & 2 deletions src/com/maxprograms/fluenta/views/AddMemoryDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.io.IOException;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.text.MessageFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.Vector;

Expand All @@ -38,6 +40,7 @@
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.json.JSONException;
import org.xml.sax.SAXException;

import com.maxprograms.fluenta.Fluenta;
Expand Down Expand Up @@ -155,10 +158,11 @@ public void widgetSelected(SelectionEvent event) {
System.getProperty("user.name"), new Date(), new Date(), srcLang, new Vector<>());
try {
mainView.getController().createMemory(mem);
} catch (IOException e) {
} catch (IOException | JSONException | ParseException e) {
logger.log(Level.ERROR, e);
MessageBox box = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
box.setMessage("Error creating memory");
MessageFormat mf = new MessageFormat("Error creating memory: {0}");
box.setMessage(mf.format(new String[] { e.getMessage() }));
box.open();
}
mainView.getMemoriesView().loadMemories();
Expand Down
5 changes: 3 additions & 2 deletions src/com/maxprograms/fluenta/views/MemoriesView.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.lang.System.Logger.Level;
import java.sql.SQLException;
import java.text.Collator;
import java.text.MessageFormat;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Comparator;
Expand Down Expand Up @@ -348,10 +349,10 @@ public int compare(Memory o1, Memory o2) {
} catch (IOException | JSONException | ParseException e) {
logger.log(Level.ERROR, e);
MessageBox box = new MessageBox(getShell(), SWT.ICON_ERROR | SWT.OK);
box.setMessage("Error loading memories");
MessageFormat mf = new MessageFormat("Error loading memories: {0}");
box.setMessage(mf.format(new String[] { e.getMessage() }));
box.open();
}

}

private void exportTMX(Memory memory) {
Expand Down
4 changes: 3 additions & 1 deletion src/com/maxprograms/fluenta/views/ProjectsView.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.text.Collator;
import java.text.MessageFormat;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Comparator;
Expand Down Expand Up @@ -337,7 +338,8 @@ public int compare(Project o1, Project o2) {
} catch (IOException | JSONException | ParseException e) {
logger.log(Level.ERROR, e);
MessageBox box = new MessageBox(getShell(), SWT.ICON_ERROR | SWT.OK);
box.setMessage("Error loading projects");
MessageFormat mf = new MessageFormat("Error loading projects: {0}");
box.setMessage(mf.format(new String[] { e.getMessage() }));
box.open();
}
}
Expand Down

0 comments on commit 44b05f8

Please sign in to comment.