X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.document.ui%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fui%2Fgraphfile%2FFileDocumentUtil.java;h=836a822b70603ff07e5195d82cfa976c1f470536;hp=9a9e3f8f10723ddb925f13ae6795df53f1ad36b2;hb=c8e675ae59eebb045a095a07e54462d0fe87f5cb;hpb=8783f9ee2b67f83160d88f43a7aef02a6b25f955 diff --git a/bundles/org.simantics.document.ui/src/org/simantics/document/ui/graphfile/FileDocumentUtil.java b/bundles/org.simantics.document.ui/src/org/simantics/document/ui/graphfile/FileDocumentUtil.java index 9a9e3f8f1..836a822b7 100644 --- a/bundles/org.simantics.document.ui/src/org/simantics/document/ui/graphfile/FileDocumentUtil.java +++ b/bundles/org.simantics.document.ui/src/org/simantics/document/ui/graphfile/FileDocumentUtil.java @@ -11,6 +11,7 @@ import java.util.HashSet; 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; @@ -63,7 +64,7 @@ public class FileDocumentUtil { } }, e -> { if (e != null) - ExceptionUtils.logAndShowError("Cannot import file " + fileName, e); + ExceptionUtils.logAndShowError(NLS.bind(Messages.FileDocumentUtil_CannotImportFile, fileName), e); }); @@ -148,7 +149,7 @@ public class FileDocumentUtil { 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) @@ -215,7 +216,7 @@ public class FileDocumentUtil { 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; @@ -295,12 +296,12 @@ public class FileDocumentUtil { 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)) { @@ -317,7 +318,7 @@ public class FileDocumentUtil { 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. @@ -337,10 +338,10 @@ public class FileDocumentUtil { * @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(); } @@ -351,11 +352,11 @@ public class FileDocumentUtil { 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); } } @@ -383,7 +384,7 @@ public class FileDocumentUtil { } 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 = '%'; @@ -413,7 +414,7 @@ public class FileDocumentUtil { 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(); @@ -433,7 +434,7 @@ public class FileDocumentUtil { 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()) { @@ -447,7 +448,7 @@ public class FileDocumentUtil { 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()) { @@ -461,7 +462,7 @@ public class FileDocumentUtil { } 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);