PentahoSolutionSpringApplicationContext extends XmlWebApplicationContext { protected Resource getResourceByPath( String path ) { Resource resource = null; String solutionPath = PentahoHttpSessionHelper.getSolutionPath( getServletContext() ); if ( solutionPath != null ) { File file = new File( solutionPath + File.separator + SYSTEM_FOLDER + File.separator + path ); resource = new FileSystemResource( file ); } else { resource = super.getResourceByPath( path ); } ClientType clientType = null; if ( KettleClientEnvironment.isInitialized( ) && KettleClientEnvironment.getInstance() != null ) { clientType = KettleClientEnvironment.getInstance().getClient(); } if ( path.toLowerCase().endsWith( DEFAULT_SPRING_XML ) && ( clientType == null || !clientType.equals( ClientType.SPOON ) ) ) { try { Document doc = getResourceDocument( resource.getInputStream() ); Node node = doc.getDocumentElement(); NodeList nodes = evaluateXPath( node, MessageFormat.format( "./{0}:{1}[@{2}=''{3}'']", DEFAULT_NAMESPASE, IMPORT_TAG, RESOURCE_ATTR, RESOURCE ), XPathConstants.NODESET ); if ( nodes.getLength() > 0 ) { return resource; } Element importEl = doc.createElementNS( node.getNamespaceURI(), IMPORT_TAG ); importEl.setAttribute( RESOURCE_ATTR, RESOURCE ); Comment comment = doc.createComment( MessageFormat.format( IMPORT_COMMENT, RESOURCE, this.getClass().getSimpleName() ) ); addLineBreak( node ); node.appendChild( comment ); addLineBreak( node ); node.appendChild( importEl ); addLineBreak( node ); TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource( doc ); FileOutputStream out = new FileOutputStream( resource.getFile() ); try { StreamResult result = new StreamResult( out ); transformer.transform( source, result ); } finally { out.flush(); out.close(); } } catch ( Exception e ) { e.printStackTrace(); } } return resource; }    }
@Test public void testGetResourceByPath() throws Exception { appContext.setServletContext( context ); File tempFile = File.createTempFile( "PentahoSolutionSpringApplicationContextTest", ".tmp" ); tempFile.deleteOnExit(); when( context.getRealPath( "" ) ).thenReturn( tempFile.getParent() ); Resource resourceByPath = appContext.getResourceByPath( tempFile.getName() ); assertNotNull( resourceByPath ); assertEquals( tempFile.getName(), resourceByPath.getFilename() ); }