private static String packOrderList(List orderList) { StringBuffer buf = new StringBuffer(); for (int i = 0; i < orderList.size(); i++) { ImportOrderEntry entry = (ImportOrderEntry) orderList.get(i); buf.append(entry.serialize()); buf.append(';'); } return buf.toString(); }
private void saveImportOrder(List elements) { IDialogSettings dialogSettings = JavaScriptPlugin.getDefault().getDialogSettings(); FileDialog dialog = new FileDialog(getShell(), SWT.SAVE); dialog.setText(PreferencesMessages.ImportOrganizeConfigurationBlock_saveDialog_title); dialog.setFilterExtensions(new String[] {"*.importorder", "*.*"}); // $NON-NLS-1$ //$NON-NLS-2$ dialog.setFileName("example.importorder"); // $NON-NLS-1$ String lastPath = dialogSettings.get(DIALOGSETTING_LASTSAVEPATH); if (lastPath != null) { dialog.setFilterPath(lastPath); } String fileName = dialog.open(); if (fileName != null) { dialogSettings.put(DIALOGSETTING_LASTSAVEPATH, dialog.getFilterPath()); Properties properties = new Properties(); for (int i = 0; i < elements.size(); i++) { ImportOrderEntry entry = (ImportOrderEntry) elements.get(i); properties.setProperty(String.valueOf(i), entry.serialize()); } FileOutputStream fos = null; try { fos = new FileOutputStream(fileName); properties.store(fos, "Organize Import Order"); // $NON-NLS-1$ } catch (IOException e) { JavaScriptPlugin.log(e); String title = PreferencesMessages.ImportOrganizeConfigurationBlock_saveDialog_error_title; String message = PreferencesMessages.ImportOrganizeConfigurationBlock_saveDialog_error_message; MessageDialog.openError(getShell(), title, message); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { } } } } }
private static ImportOrderEntry[] unpackOrderList(String str) { ArrayList res = new ArrayList(); int start = 0; do { int end = str.indexOf(';', start); if (end == -1) { end = str.length(); } res.add(ImportOrderEntry.fromSerialized(str.substring(start, end))); start = end + 1; } while (start < str.length()); return (ImportOrderEntry[]) res.toArray(new ImportOrderEntry[res.size()]); }
/* * The import order file is a property file. The keys are * "0", "1" ... last entry. The values must be valid package names. */ private List loadFromProperties(Properties properties) { ArrayList res = new ArrayList(); int nEntries = properties.size(); for (int i = 0; i < nEntries; i++) { String curr = properties.getProperty(String.valueOf(i)); if (curr != null) { ImportOrderEntry entry = ImportOrderEntry.fromSerialized(curr); if (!JavaScriptConventions.validatePackageName( entry.name, JavaScriptCore.VERSION_1_3, JavaScriptCore.VERSION_1_5) .matches(IStatus.ERROR)) { res.add(entry); } else { return null; } } else { return res; } } return res; }