Created
January 18, 2016 15:05
-
-
Save pentaho-nbaker/9d974082913340c2a48b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* This program is free software; you can redistribute it and/or modify it under the | |
* terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software | |
* Foundation. | |
* | |
* You should have received a copy of the GNU Lesser General Public License along with this | |
* program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html | |
* or from the Free Software Foundation, Inc., | |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
* | |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | |
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
* See the GNU Lesser General Public License for more details. | |
* | |
* Copyright (c) 2002-2013 Pentaho Corporation.. All rights reserved. | |
*/ | |
package org.pentaho.platform.web.http.context; | |
import org.apache.commons.io.IOUtils; | |
import org.pentaho.platform.web.http.PentahoHttpSessionHelper; | |
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | |
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; | |
import org.springframework.core.io.FileSystemResource; | |
import org.springframework.core.io.Resource; | |
import org.springframework.web.context.support.XmlWebApplicationContext; | |
import org.w3c.dom.Document; | |
import org.w3c.dom.Element; | |
import org.xml.sax.SAXException; | |
import javax.xml.parsers.DocumentBuilder; | |
import javax.xml.parsers.DocumentBuilderFactory; | |
import javax.xml.parsers.ParserConfigurationException; | |
import java.io.BufferedInputStream; | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.StringReader; | |
import java.io.StringWriter; | |
/** | |
* Overrides <code>getResourceByPath</code> so that relative paths are relative to the Pentaho solution repository's | |
* system directory instead of being relative to servlet context root. | |
* | |
* @author mlowery | |
*/ | |
public class 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" + File.separator + path ); //$NON-NLS-1$ | |
resource = new FileSystemResource( file ); | |
} else { | |
resource = super.getResourceByPath( path ); | |
} | |
if( path.endsWith( "pentaho-spring-beans.xml" ) ){ | |
try { | |
InputStream inputStream = resource.getInputStream(); | |
String string = IOUtils.toString( inputStream, "UTF-8" ); | |
if( !string.contains( "importExport.xml" ) ) { | |
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); | |
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); | |
Document document = documentBuilder.parse( string ); | |
Element anImport = document.createElement( "import" ); | |
anImport.setAttribute( "resource", "importExport.xml" ); | |
document.getDocumentElement().appendChild( anImport ); | |
} | |
} catch ( IOException e ) { | |
e.printStackTrace(); | |
} catch ( ParserConfigurationException e ) { | |
e.printStackTrace(); | |
} catch ( SAXException e ) { | |
e.printStackTrace(); | |
} | |
} | |
return resource; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment