From 86b5f400a809428e434599d20197109aa15b97c2 Mon Sep 17 00:00:00 2001 From: mka Date: Tue, 4 Dec 2012 15:35:43 +0000 Subject: [PATCH] Now som.xml can be loaded --- .../salome/SimanSalomeServiceImpl.java | 58 ++++++------------- 1 file changed, 19 insertions(+), 39 deletions(-) diff --git a/Workspace/Siman-WS/src/org/splat/ws_server/service/salome/SimanSalomeServiceImpl.java b/Workspace/Siman-WS/src/org/splat/ws_server/service/salome/SimanSalomeServiceImpl.java index d3c58bd..b20e945 100644 --- a/Workspace/Siman-WS/src/org/splat/ws_server/service/salome/SimanSalomeServiceImpl.java +++ b/Workspace/Siman-WS/src/org/splat/ws_server/service/salome/SimanSalomeServiceImpl.java @@ -16,6 +16,7 @@ import java.util.Scanner; import javax.activation.DataHandler; import javax.activation.FileDataSource; +import javax.servlet.ServletContext; import org.apache.log4j.Logger; import org.splat.kernel.InvalidPropertyException; @@ -29,8 +30,9 @@ import org.splat.service.dto.FileDTO; import org.splat.service.dto.StepDTO; import org.splat.service.technical.ProjectSettingsService; import org.splat.service.technical.RepositoryService; +import org.springframework.web.context.ServletContextAware; -public class SimanSalomeServiceImpl implements SimanSalomeService { +public class SimanSalomeServiceImpl implements SimanSalomeService, ServletContextAware { /** * The logger for the service. @@ -53,6 +55,11 @@ public class SimanSalomeServiceImpl implements SimanSalomeService { */ private ProjectSettingsService _projectSettingsService; + /** + * The Servlet Context. + */ + private ServletContext _servletContext; + /** * * {@inheritDoc} @@ -63,42 +70,7 @@ public class SimanSalomeServiceImpl implements SimanSalomeService { final Long userId) { try { - //_projectSettingsService.configure("WebContent/conf/som.xml"); - _projectSettingsService.configure("W:\\Eclipse workspace\\SIMAN\\SIMAN_SRC\\Workspace\\Siman-WS\\WebContent\\conf\\som.xml"); - //ClassLoader loader = ClassLoader.getSystemClassLoader(); - //URL pathToSOM = loader.getResource("WebContent/conf/som.xml"); - - /*ClassLoader cl = Thread.currentThread().getContextClassLoader(); - URL testURL = ClassLoader.getSystemResource("conf/som.xml"); - URL test2URL = ClassLoader.getSystemResource("som.xml"); - String path = System.getProperty("user.dir"); - - File textfile = new File("w:/testfile.txt"); - - FileWriter fstream; - try { - fstream = new FileWriter(textfile); - BufferedWriter out = new BufferedWriter(fstream); - if (testURL != null) - out.write("testURL " + testURL.getPath()); - else - out.write("testURL == null\n"); - - if (test2URL != null) - out.write("test2URL " + test2URL.getPath()); - else - out.write("test2URL == null\n"); - - out.write("path = " + path); - - out.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - }*/ - - //_projectSettingsService.configure(ClassLoader.getSystemResource("som.xml").getPath()); - //_projectSettingsService.configure(pathToSOM.getPath()); + _projectSettingsService.configure(_servletContext.getRealPath("/conf/som.xml")); } catch (IOException ioException) { LOG.debug("Sorry, IOException is throws", ioException); } catch (SQLException sqlException) { @@ -205,7 +177,7 @@ public class SimanSalomeServiceImpl implements SimanSalomeService { //will be removed in future try { - _projectSettingsService.configure("W:\\Eclipse workspace\\SIMAN\\SIMAN_SRC\\Workspace\\Siman-WS\\WebContent\\conf\\som.xml"); + _projectSettingsService.configure(_servletContext.getRealPath("/conf/som.xml")); } catch (IOException ioException) { LOG.debug("Sorry, IOException is throws", ioException); @@ -266,7 +238,9 @@ public class SimanSalomeServiceImpl implements SimanSalomeService { StepDTO step; long ScenarioId = 0; - LOG.debug("The fileURL = " + fileURL); + if (LOG.isDebugEnabled()) { + LOG.debug("The fileURL = " + fileURL); + } try { Scanner input = new Scanner(configFile); @@ -384,6 +358,12 @@ public class SimanSalomeServiceImpl implements SimanSalomeService { final ProjectSettingsService projectSettingsService) { _projectSettingsService = projectSettingsService; } + + + @Override + public void setServletContext(final ServletContext ctx) { + _servletContext = ctx; + } } -- 2.39.2