Skip to content

Commit 63d837d

Browse files
committed
Replace constants with resource bundle implementation
1 parent 818578b commit 63d837d

19 files changed

+272
-217
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#Dialog for method categories
2+
MethodDialog.Method= Method
3+
MethodDialog.UpdateTitle= Update Method
4+
MethodDialog.AddTitle= Add Method
5+
MethodDialog.Signature= Method
6+
MethodDialog.Types= Types
7+
MethodDialog.CWE = CWEs
8+
MethodDialog.Category = Category
9+
MethodDialog.AvailableCategory = Available Categories
10+
MethodDialog.SelectedCategory = Selected Categories
11+
12+
#Dialog for running SWAN
13+
Launcher.Title=Launch SWAN
14+
Launcher.ProjectCheckBox = Current Project
15+
Launcher.Project = Project
16+
Launcher.AdvancedOptionsCheckBox = Advanced Options
17+
Launcher.Output = Output Directory
18+
Launcher.TrainingJars = Training Jars
19+
20+
#Notifications when running SWAN
21+
Messages.Title.RefreshStarted = Reloading SWAN
22+
Messages.Notification.RefreshStarted = SWAN refresh started
23+
Messages.Notification.Success = SWAN execution completed
24+
Messages.Notification.Failure = There was an error
25+
Messages.Notification.EmptyTree = Select a configuration file using the \"Import\" button
26+
Messages.Notification.NoFilterResults = No methods match the filters you've selected
27+
28+
29+
#FileChooser
30+
FileChooser.FileDescription = JSON files
31+
FileChooser.FileExtension = json
32+
FileChooser.SelectDirectory = ...
33+
34+
#Error and warning Messages
35+
Messages.Error.PathNotFound= A path was not selected for one of the fields.
36+
Messages.Error.InvalidFileType = The selected file is invalid. Please select a .json file.
37+
Messages.Error.FileNotSelected = A file was not selected. Select a configuration file.
38+
Messages.Error.ElementNotSelected = Invalid element selected. Select a valid method from the class.
39+
Messages.Error.NotJavaFile = Files can only be added from a Java file.
40+
Messages.Error.MethodNotFound = The selected method was not found.
41+
Messages.Error.URINotFound = There was an error loading the URI
42+
Messages.Title.FileLoadError = File Load Error
43+
Messages.Error.FileLoadError = An error occured loading the file.
44+
Messages.Error.CategoryNotSelected = No type or CWE was selected for the method.
45+
Messages.Error.MethodNotInEditor = Method not found in project or cannot be located
46+
Messages.Error.PageNotFound = Page Not Found
47+
48+
#Confirmation messages
49+
Messages.Title.DeleteMethod = Delete Method
50+
Messages.Confirmation.DeleteMethod = Are you sure you want to delete this method?
51+
52+
Messages.Title.RestoreMethod = Restore Method
53+
Messages.Confirmation.RestoreMethod = Are you sure you want to restore this method?"
54+
55+
56+
#SWAN results dialog
57+
Results.Title=SWAN Results
58+
Results.ConfigurationFile = Configuration File
59+
Results.Logs = Output Logs
60+
61+
#Method properties Dialog
62+
Properties.Title = Method Properties
63+
Properties.Category = Property
64+
Properties.Value = Value
65+
Properties.Method = Method Name
66+
Properties.Return = Return Type
67+
Properties.Parameters = Parameter(s)
68+
Properties.Security = Security Level
69+
Properties.Discovery = Discovery
70+
Properties.Framework = Framework
71+
Properties.Link = Link
72+
Properties.CWE = CWE
73+
Properties.Type = Type
74+
Properties.Comment = Comment
75+
76+
#Filter Labels
77+
Filter.File = Current Class
78+
Filter.Clear = Clear Filters
79+
Filter.Training = Training Methods
80+
Filter.Deleted = Deleted Methods
81+
Filter.CWE = CWE
82+
Filter.Type = TYPE

swan_assist/src/de/fraunhofer/iem/swan/assist/actions/HelpAction.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
import com.intellij.notification.Notifications;
77
import com.intellij.openapi.actionSystem.AnAction;
88
import com.intellij.openapi.actionSystem.AnActionEvent;
9-
import com.intellij.openapi.actionSystem.CommonDataKeys;
10-
import com.intellij.openapi.actionSystem.PlatformDataKeys;
11-
import com.intellij.openapi.editor.Editor;
12-
import com.intellij.openapi.project.Project;
139
import com.intellij.openapi.ui.MessageType;
1410
import com.intellij.openapi.ui.popup.Balloon;
1511
import com.intellij.openapi.ui.popup.JBPopupFactory;
@@ -19,6 +15,7 @@
1915
import java.io.IOException;
2016
import java.net.URI;
2117
import java.net.URISyntaxException;
18+
import java.util.ResourceBundle;
2219

2320
/**
2421
* Action to open help page or resources.
@@ -31,26 +28,23 @@ public class HelpAction extends AnAction {
3128
@Override
3229
public void actionPerformed(AnActionEvent e) {
3330

34-
Project project = e.getData(PlatformDataKeys.PROJECT);
35-
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
36-
31+
ResourceBundle resource = ResourceBundle.getBundle("dialog_messages");
3732
URI helpUri = null;
38-
try {
39-
helpUri = new URI(Constants.HELP_LINK);
40-
} catch (URISyntaxException e1) {
41-
JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(Constants.URI_NOT_FOUND, MessageType.INFO, null)
42-
.createBalloon()
43-
.show(JBPopupFactory.getInstance().guessBestPopupLocation(editor), Balloon.Position.below);
44-
}
4533

4634
try {
35+
helpUri = new URI(Constants.HELP_LINK);
4736
Desktop.getDesktop().browse(helpUri);
48-
} catch (IOException e1) {
37+
} catch (IOException | URISyntaxException exception) {
4938

50-
JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(Constants.URI_NOT_FOUND, MessageType.INFO, null)
39+
JBPopupFactory.getInstance()
40+
.createHtmlTextBalloonBuilder(resource.getString("Messages.Error.URINotFound"), MessageType.INFO, null)
5141
.createBalloon()
52-
.show(JBPopupFactory.getInstance().guessBestPopupLocation(editor), Balloon.Position.below);
53-
Notifications.Bus.notify(new Notification("SWAN_Assist", "Page Not Found", Constants.URI_NOT_FOUND, NotificationType.ERROR));
42+
.show(JBPopupFactory.getInstance().guessBestPopupLocation(e.getDataContext()), Balloon.Position.below);
43+
44+
Notifications.Bus.notify(new Notification(Constants.PLUGIN_GROUP_DISPLAY_ID,
45+
resource.getString("Messages.Error.PageNotFound"),
46+
resource.getString("Messages.Error.URINotFound"),
47+
NotificationType.ERROR));
5448
}
5549
}
5650
}

swan_assist/src/de/fraunhofer/iem/swan/assist/actions/SwanProcessBuilder.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.time.LocalDateTime;
1111
import java.time.format.DateTimeFormatter;
1212
import java.util.HashMap;
13+
import java.util.ResourceBundle;
1314

1415

1516
/**
@@ -34,14 +35,18 @@ public class SwanProcessBuilder extends Thread {
3435
public void run() {
3536
super.run();
3637

38+
ResourceBundle resource = ResourceBundle.getBundle("dialog_messages");
39+
3740
String currentTimestamp = getCurrentTimestamp("yyyy-MM-dd-HHmmss");
3841

3942
File outputFolder = new File(parameters.get(Constants.SWAN_OUTPUT_DIR));
4043
outputFolder.mkdirs();
4144

42-
File logFile = new File(outputFolder, currentTimestamp + Constants.SWAN_LOG_SUFFIX);
45+
File logFile = new File(outputFolder, currentTimestamp + parameters.get(Constants.SWAN_OUTPUT_LOG));
4346
try {
4447
logFile.createNewFile();
48+
parameters.replace(Constants.SWAN_OUTPUT_LOG, logFile.getPath());
49+
4550
} catch (IOException e) {
4651
e.printStackTrace();
4752
}
@@ -63,19 +68,19 @@ public void run() {
6368
int result = swanProcess.waitFor();
6469

6570
if (result == 0)
66-
message = Constants.NOTIFICATION_END_SWAN_SUCCESS;
71+
message = resource.getString("Messages.Notification.Success");
6772
else
68-
message = Constants.NOTIFICATION_END_SWAN_FAIL;
73+
message = resource.getString("Messages.Notification.Failure");
6974

7075
} catch (IOException | InterruptedException e) {
7176

7277
e.printStackTrace();
73-
message = Constants.NOTIFICATION_END_SWAN_FAIL;
78+
message = resource.getString("Messages.Notification.Failure");
7479
}
7580

7681
HashMap<String, String> results = new HashMap<String, String>();
77-
results.put(Constants.SWAN_OUTPUT_FILE, parameters.get(Constants.SWAN_OUTPUT_DIR) + File.separator + "json" + File.separator + Constants.OUTPUT_JSON_SUFFIX);
78-
results.put(Constants.SWAN_OUTPUT_LOG, parameters.get(Constants.SWAN_OUTPUT_DIR) + File.separator + currentTimestamp + Constants.SWAN_LOG_SUFFIX);
82+
results.put(Constants.SWAN_OUTPUT_FILE, parameters.get(Constants.SWAN_OUTPUT_FILE));
83+
results.put(Constants.SWAN_OUTPUT_LOG, parameters.get(Constants.SWAN_OUTPUT_LOG));
7984
results.put(Constants.SWAN_OUTPUT_MESSAGE, message);
8085

8186
MessageBus messageBus = project.getMessageBus();

swan_assist/src/de/fraunhofer/iem/swan/assist/actions/method/AddMethodAction.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
import com.intellij.openapi.ui.popup.JBPopupFactory;
1111
import de.fraunhofer.iem.swan.assist.data.JSONFileLoader;
1212
import de.fraunhofer.iem.swan.assist.data.MethodWrapper;
13-
import de.fraunhofer.iem.swan.assist.util.Constants;
1413
import de.fraunhofer.iem.swan.assist.util.PsiTraversal;
1514

15+
import java.util.ResourceBundle;
16+
1617
/**
1718
* Action to add a new method by selecting a class\category.
1819
*
@@ -25,13 +26,14 @@ public class AddMethodAction extends AnAction {
2526
public void actionPerformed(AnActionEvent e) {
2627

2728
MethodWrapper method = PsiTraversal.getMethodAtOffset(e, true);
29+
ResourceBundle resource = ResourceBundle.getBundle("dialog_properties");
2830

2931
if (method != null) {
3032

3133
ActionManager.getInstance().tryToExecute(new UpdateMethodAction(method), e.getInputEvent(), null, "Add Method", false);
3234
} else {
3335
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
34-
JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(Constants.ELEMENT_NOT_SELECTED, MessageType.INFO, null)
36+
JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(resource.getString("Messages.Error.ElementNotSelected"), MessageType.INFO, null)
3537
.createBalloon()
3638
.show(JBPopupFactory.getInstance().guessBestPopupLocation(editor), Balloon.Position.below);
3739
}

swan_assist/src/de/fraunhofer/iem/swan/assist/actions/method/DeleteMethodAction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
import de.fraunhofer.iem.swan.assist.comm.MethodNotifier;
1313
import de.fraunhofer.iem.swan.assist.data.JSONFileLoader;
1414
import de.fraunhofer.iem.swan.assist.data.MethodWrapper;
15-
import de.fraunhofer.iem.swan.assist.util.Constants;
1615
import de.fraunhofer.iem.swan.assist.util.PsiTraversal;
1716

1817
import javax.swing.*;
18+
import java.util.ResourceBundle;
1919

2020
/**
2121
* Action to delete a method.
@@ -42,13 +42,13 @@ public DeleteMethodAction(MethodWrapper method) {
4242
public void actionPerformed(AnActionEvent anActionEvent) {
4343

4444
final Project project = anActionEvent.getProject();
45-
45+
ResourceBundle resource = ResourceBundle.getBundle("dialog_messages");
4646

4747
if (PsiTraversal.isFromEditor(anActionEvent))
4848
deleteMethod = PsiTraversal.getMethodAtOffset(anActionEvent, false);
4949

5050
if (deleteMethod != null) {
51-
int confirmation = JOptionPane.showConfirmDialog(null, Constants.CONFIRM_METHOD_DELETION, Constants.TITLE_DELETE_METHOD, JOptionPane.YES_NO_OPTION);
51+
int confirmation = JOptionPane.showConfirmDialog(null, resource.getString("Messages.Confirmation.DeleteMethod"), resource.getString("Messages.Title.DeleteMethod"), JOptionPane.YES_NO_OPTION);
5252

5353
if (confirmation == JOptionPane.YES_OPTION) {
5454

@@ -58,7 +58,7 @@ public void actionPerformed(AnActionEvent anActionEvent) {
5858
}
5959
} else {
6060
final Editor editor = anActionEvent.getRequiredData(CommonDataKeys.EDITOR);
61-
JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(Constants.METHOD_NOT_FOUND, MessageType.INFO, null)
61+
JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(resource.getString("Messages.Error.MethodNotFound"), MessageType.INFO, null)
6262
.createBalloon()
6363
.show(JBPopupFactory.getInstance().guessBestPopupLocation(editor), Balloon.Position.below);
6464
}

swan_assist/src/de/fraunhofer/iem/swan/assist/actions/method/MethodPropertiesAction.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
import de.fraunhofer.iem.swan.assist.data.JSONFileLoader;
1212
import de.fraunhofer.iem.swan.assist.data.MethodWrapper;
1313
import de.fraunhofer.iem.swan.assist.ui.dialog.MethodPropertiesDialog;
14-
import de.fraunhofer.iem.swan.assist.util.Constants;
1514
import de.fraunhofer.iem.swan.assist.util.PsiTraversal;
1615

16+
import java.util.ResourceBundle;
17+
1718
/**
1819
* Action to show additional properties for a method.
1920
*
@@ -38,6 +39,7 @@ public void actionPerformed(AnActionEvent anActionEvent) {
3839

3940
//Get all the required data from data keys
4041
final Project project = anActionEvent.getProject();
42+
ResourceBundle resource = ResourceBundle.getBundle("dialog_messages");
4143

4244
if (PsiTraversal.isFromEditor(anActionEvent))
4345
method = PsiTraversal.getMethodAtOffset(anActionEvent, false);
@@ -47,7 +49,7 @@ public void actionPerformed(AnActionEvent anActionEvent) {
4749
detailsDialog.show();
4850
} else {
4951
final Editor editor = anActionEvent.getRequiredData(CommonDataKeys.EDITOR);
50-
JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(Constants.METHOD_NOT_FOUND, MessageType.INFO, null)
52+
JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(resource.getString("Messages.Error.MethodNotFound"), MessageType.INFO, null)
5153
.createBalloon()
5254
.show(JBPopupFactory.getInstance().guessBestPopupLocation(editor), Balloon.Position.below);
5355
}

swan_assist/src/de/fraunhofer/iem/swan/assist/actions/method/RestoreMethodAction.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@
33
import com.intellij.openapi.actionSystem.AnAction;
44
import com.intellij.openapi.actionSystem.AnActionEvent;
55
import com.intellij.openapi.actionSystem.CommonDataKeys;
6-
import com.intellij.openapi.editor.Editor;
76
import com.intellij.openapi.project.Project;
8-
import com.intellij.openapi.ui.MessageType;
9-
import com.intellij.openapi.ui.Messages;
10-
import com.intellij.openapi.ui.popup.Balloon;
11-
import com.intellij.openapi.ui.popup.JBPopupFactory;
127
import com.intellij.util.messages.MessageBus;
138
import de.fraunhofer.iem.swan.assist.comm.MethodNotifier;
149
import de.fraunhofer.iem.swan.assist.data.JSONFileLoader;
1510
import de.fraunhofer.iem.swan.assist.data.MethodWrapper;
16-
import de.fraunhofer.iem.swan.assist.ui.SummaryToolWindow;
17-
import de.fraunhofer.iem.swan.assist.util.Constants;
11+
import de.fraunhofer.iem.swan.assist.ui.MethodListTree;
1812
import de.fraunhofer.iem.swan.assist.util.PsiTraversal;
1913

14+
import javax.swing.*;
15+
import java.util.ResourceBundle;
16+
2017
/**
2118
* Action to restore a method that was deleted after rerunning SWAN.
2219
*
@@ -40,29 +37,30 @@ public RestoreMethodAction(MethodWrapper method) {
4037
public void actionPerformed(AnActionEvent anActionEvent) {
4138

4239
final Project project = anActionEvent.getRequiredData(CommonDataKeys.PROJECT);
40+
ResourceBundle resource = ResourceBundle.getBundle("dialog_messages");
4341

4442
if (PsiTraversal.isFromEditor(anActionEvent))
4543
method = PsiTraversal.getMethodAtOffset(anActionEvent, false);
4644

4745
if (method != null) {
48-
//Notify Summary Tool window that new method was restored
49-
MessageBus messageBus = project.getMessageBus();
50-
MethodNotifier publisher = messageBus.syncPublisher(MethodNotifier.METHOD_UPDATED_ADDED_TOPIC);
51-
publisher.afterAction(method);
52-
53-
Messages.showMessageDialog(project, Constants.MSG_METHOD_RESTORED, Constants.TITLE_RESTORE_METHOD, Messages.getInformationIcon());
54-
} else {
55-
final Editor editor = anActionEvent.getRequiredData(CommonDataKeys.EDITOR);
56-
JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(Constants.METHOD_NOT_FOUND, MessageType.INFO, null)
57-
.createBalloon()
58-
.show(JBPopupFactory.getInstance().guessBestPopupLocation(editor), Balloon.Position.below);
46+
47+
int confirmation = JOptionPane.showConfirmDialog(null, resource.getString("Messages.Confirmation.RestoreMethod"), resource.getString("Messages.Title.RestoreMethod"), JOptionPane.YES_NO_OPTION);
48+
49+
if (confirmation == JOptionPane.YES_OPTION) {
50+
51+
//Notify Summary Tool window that new method was restored
52+
method.setUpdateOperation(null);
53+
MessageBus messageBus = project.getMessageBus();
54+
MethodNotifier publisher = messageBus.syncPublisher(MethodNotifier.METHOD_UPDATED_ADDED_TOPIC);
55+
publisher.afterAction(method);
56+
}
5957
}
6058
}
6159

6260
@Override
6361
public void update(AnActionEvent event) {
6462

65-
if (SummaryToolWindow.RESTORE_METHOD && JSONFileLoader.isFileSelected())
63+
if (MethodListTree.RESTORE_METHOD && JSONFileLoader.isFileSelected())
6664
event.getPresentation().setEnabled(true);
6765
else
6866
event.getPresentation().setEnabled(false);

swan_assist/src/de/fraunhofer/iem/swan/assist/data/JSONFileParser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import de.fraunhofer.iem.swan.data.Method;
99

1010
import java.util.HashMap;
11+
import java.util.ResourceBundle;
1112

1213
public class JSONFileParser {
1314

@@ -30,6 +31,7 @@ public HashMap<String, MethodWrapper> parseJSONFileMap() {
3031

3132
HashMap<String, MethodWrapper> methods = new HashMap<String, MethodWrapper>();
3233
Parser parser = new Parser(null);
34+
ResourceBundle resource = ResourceBundle.getBundle("dialog_messages");
3335

3436
try {
3537
for (Method method : parser.parseFile(congFilePath)) {
@@ -44,7 +46,7 @@ public HashMap<String, MethodWrapper> parseJSONFileMap() {
4446
methods.put(methodWrapper.getSignature(true), methodWrapper);
4547
}
4648
} catch (Exception e) {
47-
Notifications.Bus.notify(new Notification("SWAN_Assist", "File Load Error", Constants.FILE_LOAD_ERROR, NotificationType.ERROR));
49+
Notifications.Bus.notify(new Notification("SWAN_Assist", resource.getString("Messages.Title.FileLoadError"), resource.getString("Messages.Error.FileLoadError"), NotificationType.ERROR));
4850
}
4951

5052
return methods;

swan_assist/src/de/fraunhofer/iem/swan/assist/data/JSONWriter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ public void writeToJsonFile(ArrayList<MethodWrapper> methods, String outputPath)
2121

2222
Writer writer = new Writer();
2323
writer.printResultsJSON(methodSet, outputPath);
24-
2524
}
2625
}

0 commit comments

Comments
 (0)