Search in sources :

Example 16 with IPentahoUrlFactory

use of org.pentaho.platform.api.engine.IPentahoUrlFactory in project pentaho-platform by pentaho.

the class GeneratorStreamingOutput method generateContent.

protected void generateContent(OutputStream outputStream, final MimeTypeCallback callback) throws Exception {
    try {
        httpServletResponse.setCharacterEncoding(LocaleHelper.getSystemEncoding());
    } catch (Throwable t) {
        // $NON-NLS-1$
        logger.warn("could not set encoding, servlet-api is likely too old.  are we in a unit test?");
    }
    IOutputHandler outputHandler = new HttpOutputHandler(httpServletResponse, outputStream, true);
    outputHandler.setMimeTypeListener(new HttpMimeTypeListener(httpServletRequest, httpServletResponse) {

        /*
       * This content generator is setting the mimeType
       */
        @Override
        public void setMimeType(String mimeType) {
            try {
                if (!MIMETYPE_MUTABLE && GeneratorStreamingOutput.this.getMimeType() != null) {
                    mimeTrace(// $NON-NLS-1$
                    "Content generator is trying to set response mime type to [{0}], but mime type [{1}] has already been imposed. Content generator request to change mime type will be ignored.", mimeType, GeneratorStreamingOutput.this.getMimeType());
                    return;
                } else {
                    // $NON-NLS-1$
                    mimeTrace("Content generator is setting response mime type to [{0}]", mimeType);
                    if (callback != null) {
                        callback.setMimeType(mimeType);
                    }
                    GeneratorStreamingOutput.this.setMimeType(mimeType);
                }
            } catch (Throwable th) {
                mimeTrace("Failed to set mime type: {0}", th.getMessage());
                // $NON-NLS-1$
                logger.error(MessageFormat.format("Failed to set mime type: {0}", th.getMessage()));
            }
            super.setMimeType(mimeType);
        }
    });
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    parameterProviders.put(IParameterProvider.SCOPE_REQUEST, createRequestParamProvider());
    parameterProviders.put(IParameterProvider.SCOPE_SESSION, createSessionParameterProvider());
    // $NON-NLS-1$
    parameterProviders.put("headers", createHeaderParamProvider());
    // $NON-NLS-1$
    parameterProviders.put("path", createPathParamProvider());
    String pluginId = contentGeneratorDescriptor.getPluginId();
    IPentahoUrlFactory urlFactory = new SimpleUrlFactory(PentahoRequestContextHolder.getRequestContext().getContextPath() + "api/repos/" + pluginId + "/" + contentGeneratorID + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "?");
    // set the classloader of the current thread to the class loader of
    // the plugin so that it can load its libraries
    // Note: we cannot ask the contentGenerator class for it's classloader,
    // since the cg may
    // actually be a proxy object loaded by main the WebAppClassloader
    ClassLoader origContextClassloader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(pluginMgr.getClassLoader(pluginId));
    try {
        contentGenerator.setOutputHandler(outputHandler);
        contentGenerator.setMessagesList(new ArrayList<String>());
        contentGenerator.setParameterProviders(parameterProviders);
        contentGenerator.setSession(PentahoSessionHolder.getSession());
        if (urlFactory != null) {
            contentGenerator.setUrlFactory(urlFactory);
        }
        contentGenerator.createContent();
    } finally {
        Thread.currentThread().setContextClassLoader(origContextClassloader);
    }
}
Also used : IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) HashMap(java.util.HashMap) HttpOutputHandler(org.pentaho.platform.web.http.HttpOutputHandler) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) HttpMimeTypeListener(org.pentaho.platform.web.http.HttpMimeTypeListener) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory)

Example 17 with IPentahoUrlFactory

use of org.pentaho.platform.api.engine.IPentahoUrlFactory in project data-access by pentaho.

the class DSWDatasourceServiceImpl method listDatasourceNames.

public List<String> listDatasourceNames() throws IOException {
    synchronized (CsvDatasourceServiceImpl.lock) {
        // $NON-NLS-1$
        IPentahoUrlFactory urlFactory = new SimpleUrlFactory("");
        PMDUIComponent component = new PMDUIComponent(urlFactory, new ArrayList());
        component.validate(PentahoSessionHolder.getSession(), null);
        component.setAction(PMDUIComponent.ACTION_LIST_MODELS);
        Document document = component.getXmlContent();
        // $NON-NLS-1$
        List<DefaultElement> modelElements = document.selectNodes("//model_name");
        ArrayList<String> datasourceNames = new ArrayList<String>();
        for (DefaultElement element : modelElements) {
            datasourceNames.add(element.getText());
        }
        return datasourceNames;
    }
}
Also used : IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) DefaultElement(org.dom4j.tree.DefaultElement) ArrayList(java.util.ArrayList) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) PMDUIComponent(org.pentaho.platform.uifoundation.component.xml.PMDUIComponent) Document(org.dom4j.Document)

Aggregations

IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)17 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)17 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)9 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)8 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)8 OutputStream (java.io.OutputStream)6 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)6 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)6 IOException (java.io.IOException)5 IPentahoRequestContext (org.pentaho.platform.api.engine.IPentahoRequestContext)5 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)5 Document (org.dom4j.Document)4 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)4 PMDUIComponent (org.pentaho.platform.uifoundation.component.xml.PMDUIComponent)4 File (java.io.File)3 FileReader (java.io.FileReader)3 Reader (java.io.Reader)3 List (java.util.List)3 ActionComponent (org.pentaho.platform.uifoundation.component.ActionComponent)3