import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.osgi.util.NLS;
import org.simantics.Simantics;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
}
}, e -> {
if (e != null)
- ExceptionUtils.logAndShowError("Cannot import file " + fileName, e);
+ ExceptionUtils.logAndShowError(NLS.bind(Messages.FileDocumentUtil_CannotImportFile, fileName), e);
});
public static void importFolder(WriteGraph graph, File folder, Resource folderResource, Resource relation, IProgressMonitor monitor) throws Exception{
if (monitor != null) {
int count = _countFiles(folder);
- monitor.beginTask("Import files", count);
+ monitor.beginTask(Messages.FileDocumentUtil_MonitorImportFiles, count);
}
_importFolder(graph, folder, folderResource, relation, monitor);
if (monitor != null)
return;
int i = 1;
while (true) {
- String proposal = name +" (" + i +")";
+ String proposal = name +" (" + i +")"; //$NON-NLS-1$ //$NON-NLS-2$
if (!names.contains(proposal)) {
graph.claimLiteral(res, l0.HasName, proposal);
return;
name = graph.getRelatedValue(r, useResourceNames ? gf.HasResourceName : l0.HasName);
canExport = true;
} else if (graph.isInstanceOf(r, doc.UrlDocument)) {
- name = graph.getRelatedValue(r, l0.HasName) +".url";
+ name = graph.getRelatedValue(r, l0.HasName) +".url"; //$NON-NLS-1$
canExport = true;
}
if (canExport) {
name = resolveName(folder, name, names, true);
- File file = new File(folder.getAbsolutePath()+"/"+name);
+ File file = new File(folder.getAbsolutePath()+"/"+name); //$NON-NLS-1$
if (graph.isInstanceOf(r, doc.FileDocument)) {
GraphFileUtil.writeDataToFile(graph,r, file);
} else if (graph.isInstanceOf(r, doc.UrlDocument)) {
if (type.size() == folderType.size() && folderType.containsAll(type)) {
String name = graph.getRelatedValue(r, l0.HasName);
name = resolveName(folder, name, names, false);
- File subFolder = new File(folder.getAbsolutePath()+"/"+name);
+ File subFolder = new File(folder.getAbsolutePath()+"/"+name); //$NON-NLS-1$
if (!subFolder.exists()) {
if (!subFolder.mkdir()) {
// TODO : error.
* @throws DatabaseException
*/
private static void exportUrl(File toFile, String name, String url) throws Exception{
- PrintStream os = new PrintStream(toFile,"UTF-8");
- os.println("[InternetShortcut]");
- os.println("URL="+url);
- os.println("name="+name);
+ PrintStream os = new PrintStream(toFile,"UTF-8"); //$NON-NLS-1$
+ os.println("[InternetShortcut]"); //$NON-NLS-1$
+ os.println("URL="+url); //$NON-NLS-1$
+ os.println("name="+name); //$NON-NLS-1$
os.flush();
os.close();
}
String name = null;
BufferedReader is = null;
try {
- is = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
+ is = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); //$NON-NLS-1$
while ((s = is.readLine()) != null) {
- if (s.startsWith("URL=")) {
+ if (s.startsWith("URL=")) { //$NON-NLS-1$
url = s.substring(4);
- } else if (s.startsWith("name=")) {
+ } else if (s.startsWith("name=")) { //$NON-NLS-1$
name = s.substring(5);
}
}
}
private static boolean isUrl(File file) throws Exception{
- return (file.getAbsolutePath().endsWith(".url"));
+ return (file.getAbsolutePath().endsWith(".url")); //$NON-NLS-1$
}
private static final char ESCAPE = '%';
for (int i = 0; i < len; i++) {
char ch = s.charAt(i);
if (ch == ESCAPE) {
- String num = "0x";
+ String num = "0x"; //$NON-NLS-1$
num += s.charAt(++i);
num += s.charAt(++i);
ch = (char)Integer.decode(num).intValue();
if (used.contains(current)) {
current = createFileName(proposal, i);
} else {
- File subFile = new File(parentFolder.getAbsolutePath()+"/"+current);
+ File subFile = new File(parentFolder.getAbsolutePath()+"/"+current); //$NON-NLS-1$
if (!subFile.exists())
break;
if (subFile.exists() && subFile.isFile() && subFile.canWrite()) {
if (used.contains(current)) {
current = proposal+i;
} else {
- File subFolder = new File(parentFolder.getAbsolutePath()+"/"+current);
+ File subFolder = new File(parentFolder.getAbsolutePath()+"/"+current); //$NON-NLS-1$
if (!subFolder.exists())
break;
if (subFolder.exists() && subFolder.isDirectory()) {
}
private static String createFileName(String original, int i) {
- int extIndex = original.lastIndexOf(".");
+ int extIndex = original.lastIndexOf("."); //$NON-NLS-1$
if (extIndex == -1)
return original+i;
return original.substring(0,extIndex) + i + original.substring(extIndex);