From abfdbd068fa095e2d122278a164643cb60fd8d25 Mon Sep 17 00:00:00 2001 From: Antoine ELIAS Date: Tue, 4 Mar 2014 10:52:33 +0100 Subject: [PATCH] xml load take care of scilab current directory Change-Id: I8566dd6029173d9e6d07f3c03e538f31d721c5a4 --- .../graphic_objects/xmlloader/XMLDomLoader.java | 50 ++++++++++++++++---- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/xmlloader/XMLDomLoader.java b/scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/xmlloader/XMLDomLoader.java index db5d995..ba7ddf7 100644 --- a/scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/xmlloader/XMLDomLoader.java +++ b/scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/xmlloader/XMLDomLoader.java @@ -9,6 +9,7 @@ import java.util.StringTokenizer; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; +import org.scilab.modules.commons.CommonFileUtils; import org.scilab.modules.commons.gui.FindIconHelper; import org.scilab.modules.graphic_objects.builder.Builder; import org.scilab.modules.graphic_objects.console.Console; @@ -198,19 +199,52 @@ public class XMLDomLoader { public int parse(String filename) { try { this.filename = filename; - File file = new File(filename); + File f = new File(filename); + String currentPath = ""; + + if (f.exists()) { + //add filename filepath in ScilabSwingUtilities paths + if (f.isAbsolute()) { + String filePath = f.getAbsolutePath(); + currentPath = filePath.substring(0, filePath.lastIndexOf(File.separator)); + FindIconHelper.addThemePath(currentPath); + } else { + String initialDirectoryPath = CommonFileUtils.getCWD(); + String filePath = ""; + Integer index = filename.lastIndexOf(File.separator); + if (index != -1) { + filePath = filename.substring(0, index); + } + + currentPath = initialDirectoryPath + File.separator + filePath; + FindIconHelper.addThemePath(currentPath); - if (file.exists()) { - //add filename filepath in FindIconHelper paths - String absoluteFilePath = file.getAbsolutePath(); - String path = absoluteFilePath.substring(0, absoluteFilePath.lastIndexOf(File.separator)); - FindIconHelper.addThemePath(path); + f = new File(currentPath + File.separator + filename); + } } else { - return 1; + //try to find file in currentPath + if (f.isAbsolute()) { + //failed + return 1; + } else { + String initialDirectoryPath = CommonFileUtils.getCWD(); + String filePath = ""; + Integer index = filename.lastIndexOf(File.separator); + if (index != -1) { + filePath = filename.substring(0, index); + } + + currentPath = initialDirectoryPath + File.separator + filePath; + } + + f = new File(currentPath + File.separator + filename); + if (f.exists() == false) { + return 1; + } } DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = dBuilder.parse(file); + Document doc = dBuilder.parse(f); doc.getDocumentElement().normalize(); if (doc.hasChildNodes()) { -- 1.7.9.5