Example usage for org.apache.commons.vfs FileSystemManager resolveFile

List of usage examples for org.apache.commons.vfs FileSystemManager resolveFile

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileSystemManager resolveFile.

Prototype

public FileObject resolveFile(String name) throws FileSystemException;

Source Link

Document

Locates a file by name.

Usage

From source file:org.pentaho.agilebi.test.MetadataToMondrianVfsTest.java

@Test
public void testVfs() throws Exception {

    ((DefaultFileSystemManager) VFS.getManager()).addProvider("mtm", new MetadataToMondrianVfs());

    FileSystemManager fsManager = VFS.getManager();
    FileObject fobj = fsManager.resolveFile("mtm:test-res/example_olap.xmi");
    StringBuilder buf = new StringBuilder(1000);
    InputStream in = fobj.getContent().getInputStream();
    int n;/*  w w w  . ja va2  s.co m*/
    while ((n = in.read()) != -1) {
        buf.append((char) n);
    }
    in.close();
    String results = buf.toString();
    Assert.assertTrue(results.indexOf("<Cube name=\"customer2 Table\">") >= 0);
}

From source file:org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogHelper.java

protected String docAtUrlToString(final String urlStr, final IPentahoSession pentahoSession) {
    // String relPath = getSolutionRepositoryRelativePath(urlStr, pentahoSession);

    String res = null;//from   www  .ja v  a  2s .  c o  m
    InputStream in = null;
    try {
        LocalizingDynamicSchemaProcessor schemaProcessor = new LocalizingDynamicSchemaProcessor();
        PropertyList localeInfo = new PropertyList();
        localeInfo.put("Locale", getLocale().toString()); //$NON-NLS-1$

        FileSystemManager fsManager = VFS.getManager();

        SolutionRepositoryVfsFileObject mondrianDS = (SolutionRepositoryVfsFileObject) fsManager
                .resolveFile(urlStr);

        in = mondrianDS.getInputStream();
        res = schemaProcessor.filter(null, localeInfo, in);
    } catch (FileNotFoundException fnfe) {
        throw new MondrianCatalogServiceException(
                Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0007_FILE_NOT_FOUND"), fnfe); //$NON-NLS-1$
    } catch (Exception e) {
        throw new MondrianCatalogServiceException(
                Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0006_IO_PROBLEM"), e); //$NON-NLS-1$
    } finally {
        IOUtils.closeQuietly(in);
    }
    return res;
}

From source file:org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogHelper.java

protected String getSolutionRepositoryRelativePath(final String path, final IPentahoSession pentahoSession) {

    try {/*from w  ww.j a  va 2 s  .  co  m*/
        FileSystemManager fsManager = VFS.getManager();
        return fsManager.resolveFile(path).getName().getPath();
    } catch (FileSystemException e) {
        throw new MondrianCatalogServiceException(
                Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0012_FILESYSTEM_PROBLEM"), //$NON-NLS-1$
                e);
    }

}

From source file:org.pentaho.platform.plugin.outputs.ApacheVFSOutputHandler.java

@Override
public IContentItem getFileOutputContentItem() {

    String contentRef = getContentRef();
    try {//from  w w w. j ava  2  s .  c  om
        String contentName = getHandlerId().substring(4) + ":" + contentRef; //$NON-NLS-1$
        FileSystemManager fsManager = VFS.getManager();
        if (fsManager == null) {
            Logger.error(ApacheVFSOutputHandler.class.getName(),
                    Messages.getInstance().getString("ApacheVFSOutputHandler.ERROR_0001_CANNOT_GET_VFSMGR")); //$NON-NLS-1$
            return null;
        }
        FileObject file = fsManager.resolveFile(contentName);
        if (file == null) {
            Logger.error(ApacheVFSOutputHandler.class.getName(), Messages.getInstance()
                    .getString("ApacheVFSOutputHandler.ERROR_0002_CANNOT_GET_VF", contentName)); //$NON-NLS-1$
            return null;
        }
        if (!file.isWriteable()) {
            Logger.error(ApacheVFSOutputHandler.class.getName(), Messages.getInstance()
                    .getString("ApacheVFSOutputHandler.ERROR_0003_CANNOT_WRITE", contentName)); //$NON-NLS-1$
            return null;
        }
        FileContent fileContent = file.getContent();
        if (fileContent == null) {
            Logger.error(ApacheVFSOutputHandler.class.getName(), Messages.getInstance()
                    .getString("ApacheVFSOutputHandler.ERROR_0004_CANNOT_GET_CTX", contentName)); //$NON-NLS-1$
            return null;
        }
        OutputStream outputStream = fileContent.getOutputStream();

        SimpleContentItem content = new SimpleContentItem(outputStream);
        return content;
    } catch (Throwable t) {
        Logger.error(ApacheVFSOutputHandler.class.getName(), Messages.getInstance()
                .getString("ApacheVFSOutputHandler.ERROR_0005_CANNOT_GET_HANDLER", contentRef), t); //$NON-NLS-1$
    }

    return null;
}

From source file:org.pentaho.platform.web.servlet.PentahoXmlaServlet.java

@Override
protected CatalogLocator makeCatalogLocator(ServletConfig servletConfig) {
    return new ServletContextCatalogLocator(servletConfig.getServletContext()) {
        @Override//from  ww w  .j  a v  a  2s  .  c  o m
        public String locate(String catalogPath) {
            if (catalogPath.startsWith("mondrian:")) { //$NON-NLS-1$
                try {
                    FileSystemManager fsManager = VFS.getManager();
                    SolutionRepositoryVfsFileObject catalog = (SolutionRepositoryVfsFileObject) fsManager
                            .resolveFile(catalogPath);
                    catalogPath = "solution:" + catalog.getFileRef();
                } catch (FileSystemException e) {
                    logger.error(e.getMessage());
                }
            } else {
                catalogPath = super.locate(catalogPath);
            }
            return catalogPath;
        }
    };
}

From source file:org.richfaces.cdk.rd.mojo.ResourceDependencyMojo.java

protected FileObject resolveArtifact(Artifact artifact) {
    FileObject jarFileObjects = null;

    if (artifact != null) {

        try {/*from   w  w w.ja va2  s  .c o m*/
            resolver.resolve(artifact, Collections.EMPTY_LIST, localRepository);
            if (getLog().isDebugEnabled()) {
                getLog().debug("artifact " + artifact.getFile().toURI() + " is resolved");
            }
        } catch (ArtifactResolutionException e) {
            getLog().error(
                    "Error with resolve artifact " + artifact.getFile().getPath() + "\n" + e.getMessage(), e);
        } catch (ArtifactNotFoundException e) {
            getLog().error("Not found artifact " + artifact.getFile().toURI() + "\n" + e.getMessage(), e);
        }

        File file = artifact.getFile();

        try {
            FileSystemManager manager = VFS.getManager();
            jarFileObjects = manager.resolveFile("jar:" + file.toURI());
        } catch (FileSystemException e) {
            getLog().error("Error during processing file: " + file.toURI() + "\n" + e.getMessage(), e);
        }

    }

    return jarFileObjects;
}

From source file:org.saiku.adhoc.providers.impl.standalone.StandaloneCdaProvider.java

public void setPath(String path) {

    FileSystemManager fileSystemManager;
    try {/*  w  ww .j a  v  a2  s  . c om*/
        fileSystemManager = VFS.getManager();

        FileObject fileObject;
        fileObject = fileSystemManager.resolveFile(path);
        if (fileObject == null) {
            throw new IOException("File cannot be resolved: " + path);
        }
        if (!fileObject.exists()) {
            throw new IOException("File does not exist: " + path);
        }
        repoURL = fileObject.getURL();
        if (repoURL == null) {
            throw new Exception("Cannot load connection repository from path: " + path);
        } else {
            load();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:org.saiku.service.importer.impl.LegacyImporterImpl.java

private void setPath(String path) {

    FileSystemManager fileSystemManager;
    try {/*from w ww.  j  a  v  a 2s .  c  o  m*/
        fileSystemManager = VFS.getManager();

        FileObject fileObject;
        fileObject = fileSystemManager.resolveFile(path);
        if (fileObject == null) {
            throw new IOException("File cannot be resolved: " + path);
        }
        if (!fileObject.exists()) {
            throw new IOException("File does not exist: " + path);
        }
        repoURL = fileObject.getURL();
        if (repoURL == null) {
            throw new Exception("Cannot load connection repository from path: " + path);
        } else {
            //load();
        }
    } catch (Exception e) {
        LOG.error("Exception", e);
    }

}

From source file:org.saiku.web.rest.resources.BasicRepositoryResource.java

public void setPath(String path) throws Exception {

    FileSystemManager fileSystemManager;
    try {//from ww w  . j  a  v  a  2s.com
        if (!path.endsWith("" + File.separatorChar)) {
            path += File.separatorChar;
        }
        fileSystemManager = VFS.getManager();
        FileObject fileObject;
        fileObject = fileSystemManager.resolveFile(path);
        if (fileObject == null) {
            throw new IOException("File cannot be resolved: " + path);
        }
        if (!fileObject.exists()) {
            throw new IOException("File does not exist: " + path);
        }
        repo = fileObject;
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:org.saiku.web.rest.resources.BasicRepositoryResource2.java

public void setPath(String path) throws Exception {
    FileSystemManager fileSystemManager;
    try {/*w w  w. j  ava 2  s  .  c  o m*/
        if (!path.endsWith("" + File.separatorChar)) {
            path += File.separatorChar;
        }
        fileSystemManager = VFS.getManager();
        FileObject fileObject;
        fileObject = fileSystemManager.resolveFile(path);
        if (fileObject == null) {
            throw new IOException("File cannot be resolved: " + path);
        }
        if (!fileObject.exists()) {
            throw new IOException("File does not exist: " + path);
        }
        repo = fileObject;
    } catch (Exception e) {
        log.error("Error setting path for repository: " + path, e);
    }
}