Example usage for org.apache.commons.vfs2 FileSystemException FileSystemException

List of usage examples for org.apache.commons.vfs2 FileSystemException FileSystemException

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileSystemException FileSystemException.

Prototype

public FileSystemException(final Throwable throwable) 

Source Link

Document

Constructs wrapper exception.

Usage

From source file:org.pentaho.hadoop.shim.HadoopConfigurationFileSystemManager.java

/**
 * Get the file provider for the scheme registered for the configuration provided
 *
 * @param config Hadoop configuration to look up scheme by
 * @param scheme URI scheme to look up file provider by
 * @return A File Provider registered for the configuration that supports the provided scheme
 * @throws FileSystemException//from  w  w w  . java2 s .  co m
 */
public FileProvider getFileProvider(HadoopConfiguration config, String scheme) throws FileSystemException {
    Map<String, FileProvider> providers = providersByConfiguration.get(config);
    FileProvider p = null;
    if (providers != null) {
        p = providers.get(scheme);
    }
    if (p == null) {
        throw new FileSystemException(BaseMessages.getString(PKG, "Error.UnsupportedSchemeForConfiguration",
                config.getName(), scheme));
    }
    return p;
}

From source file:org.pentaho.hadoop.shim.HadoopConfigurationFileSystemManager.java

/**
 * Get the file provider for the active Hadoop configuration that is registered for the scheme provided.
 *
 * @param scheme URI scheme to look up file provider by
 * @return A File Provider registered for the active Hadoop configuration that supports the provided scheme
 * @throws FileSystemException If the active configuration cannot be determined or the active configuration doesn't
 *                             support the provided scheme
 *//*  w  w  w  . j a va2  s .c  o m*/
public FileProvider getActiveFileProvider(String scheme) throws FileSystemException {
    try {
        return getFileProvider(configProvider.getActiveConfiguration(), scheme);
    } catch (ConfigurationException e) {
        throw new FileSystemException(e);
    }
}

From source file:org.pentaho.reporting.libraries.pensol.JCRSolutionDirectFileModel.java

private RepositoryFileTreeDto getFileTree() throws FileSystemException {
    /*/*from w ww.j  av  a2 s  .  co m*/
    /api/repo/files/tree?depth=-1&filter=*&showHidden=true
    public RepositoryFileTreeDto doGetRootTree(
      @QueryParam( "depth" ) Integer depth,
      @QueryParam( "filter" ) String filter,
      @QueryParam( "showHidden" ) Boolean showHidden,
      @DefaultValue( "false" ) @QueryParam( "includeAcls" ) Boolean includeAcls )
    */

    final int depth = -1;
    final String filter = "*";
    final boolean showHidden = true;

    RepositoryFileTreeDto fileTree = null;
    if (this.doGetRootChildrenMethod == null) {
        fileTree = this.fileRes.doGetRootTree(depth, filter, showHidden, false);
    } else {
        // apply [5.0-SNAPSHOT] backport
        try {
            fileTree = (RepositoryFileTreeDto) this.doGetRootChildrenMethod.invoke(this.fileRes, depth, filter,
                    showHidden);
        } catch (InvocationTargetException e) {
            throw new FileSystemException(FAILED_TO_ACCESS_REPOSITORY);
        } catch (IllegalAccessException e) {
            throw new FileSystemException(FAILED_TO_ACCESS_REPOSITORY);
        }
    }
    return fileTree;
}

From source file:org.pentaho.reporting.libraries.pensol.JCRSolutionDirectFileModel.java

private void throwExceptionOnBadResponse(Response response) throws FileSystemException {
    final int status = response.getStatus();
    switch (status) {
    case HttpStatus.SC_OK:
        logger.debug("OK");
        // response OK => do not throw exception and continue execution
        break;//from  w ww . j av a 2s  .c  o  m

    case HttpStatus.SC_UNAUTHORIZED:
    case HttpStatus.SC_FORBIDDEN:
    case HttpStatus.SC_MOVED_TEMPORARILY:
        logger.debug("FORBIDDEN");
        throw new FileSystemException(INVALID_USERNAME_OR_PASSWORD);

    default:
        logger.debug("ERROR " + status);
        throw new FileSystemException(BAD_RESPONSE, status);
    }
}

From source file:org.pentaho.reporting.libraries.pensol.JCRSolutionDirectFileModel.java

@Override
public String[] getChilds(final FileName fullName) throws FileSystemException {
    logger.debug("getChilds: " + fullName);

    final List<RepositoryFileTreeDto> children = getChildNodes(fullName);
    logger.debug("size = " + children.size());

    final String[] childrenArray = new String[children.size()];
    for (int i = 0; i < children.size(); i++) {
        final RepositoryFileTreeDto treeNode = children.get(i);
        if (treeNode != null) {
            final RepositoryFileDto file = treeNode.getFile();
            if (file != null) {
                logger.debug("file " + file.getName());
                childrenArray[i] = file.getName();
            } else {
                throw new FileSystemException(NULL_OBJECT);
            }//from w w w  . j  av a 2 s  .c o  m
        }
    }
    return childrenArray;
}

From source file:org.pentaho.reporting.libraries.pensol.JCRSolutionDirectFileModel.java

@Override
public byte[] getData(final FileName fullName) throws FileSystemException {
    /*//www .  j  ava2s .c  o m
    /api/repo/files/{0}/download?withManifest=false
    public Response doGetFileOrDirAsDownloadMethod(
      @PathParam("pathId") String pathId,
      @QueryParam("withManifest") String strWithManifest )
    */
    logger.debug("getData: " + fullName);

    try {
        final String fileId = pathToId(fullName.getPath());
        Response response = null;
        if (this.doGetFileOrDirAsDownloadMethod == null) {
            response = this.fileRes.doGetFileOrDirAsDownload("", fileId, "false");
        } else {
            // apply [5.0-SNAPSHOT] backport
            try {
                response = (Response) this.doGetFileOrDirAsDownloadMethod.invoke(this.fileRes, fileId, "false");
            } catch (InvocationTargetException e) {
                throw new FileSystemException(FAILED_TO_ACCESS_REPOSITORY);
            } catch (IllegalAccessException e) {
                throw new FileSystemException(FAILED_TO_ACCESS_REPOSITORY);
            }
        }
        throwExceptionOnBadResponse(response);
        StreamingOutput output = (StreamingOutput) response.getEntity();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        output.write(stream);
        return stream.toByteArray();
    } catch (FileNotFoundException e) {
        throw new FileSystemException(FILE_NOT_FOUND, fullName);
    } catch (IOException e) {
        throw new FileSystemException(FAILED_TO_WRITE_FILE, fullName);
    }
}

From source file:org.pentaho.reporting.libraries.pensol.JCRSolutionFileModel.java

protected RepositoryFileTreeDto lookupNode(final String[] path) throws FileSystemException {
    if (root == null) {
        try {//  ww w  .  j  a  v  a2  s  .c o  m
            refresh();
        } catch (IOException e) {
            throw new FileSystemException(e);
        }
    }
    if (path.length == 0) {
        return root;
    }
    if ("".equals(path[0])) {
        if (path.length == 1) {
            return root;
        }
    }
    RepositoryFileTreeDto element = root;
    for (final String pathSegment : path) {
        RepositoryFileTreeDto name = null;
        final List<RepositoryFileTreeDto> children = element.getChildren();
        if (children == null) {
            return null;
        }

        for (final RepositoryFileTreeDto child : children) {
            final RepositoryFileDto file = child.getFile();
            if (file == null) {
                throw new FileSystemException(BI_SERVER_NULL_OBJECT);
            }
            if (pathSegment.equals(file.getName())) {
                name = child;
                break;
            }
        }
        if (name == null) {
            return null;
        }
        element = name;
    }
    return element;
}

From source file:org.pentaho.reporting.libraries.pensol.JCRSolutionFileModel.java

public void setData(final FileName file, final byte[] data) throws FileSystemException {
    final String[] fileName = computeFileNames(file);
    final StringBuilder b = new StringBuilder();
    for (int i = 0; i < fileName.length; i++) {
        if (i != 0) {
            b.append(SLASH);/*w  w  w . j  av  a 2  s  . c  om*/
        }
        b.append(fileName[i]);
    }

    String service = MessageFormat.format(UPLOAD_SERVICE, URLEncoder
            .encodeUTF8(normalizePath(b.toString()).replaceAll("\\!", "%21").replaceAll("\\+", "%2B")));
    final WebResource resource = client.resource(url + service);
    final ByteArrayInputStream stream = new ByteArrayInputStream(data);
    final ClientResponse response = resource.put(ClientResponse.class, stream);
    final int status = response.getStatus();

    if (status != HttpStatus.SC_OK) {
        if (status == HttpStatus.SC_MOVED_TEMPORARILY || status == HttpStatus.SC_FORBIDDEN
                || status == HttpStatus.SC_UNAUTHORIZED) {
            throw new FileSystemException("ERROR_INVALID_USERNAME_OR_PASSWORD");
        } else {
            throw new FileSystemException("ERROR_FAILED", status);
        }
    }

    try {
        // Perhaps a New file was created. Refresh local tree model.
        this.refresh();
    } catch (IOException e) {
        // Ignore if unable to refresh
    }
}

From source file:org.pentaho.reporting.libraries.pensol.JCRSolutionFileModel.java

public String[] getChilds(final FileName name) throws FileSystemException {
    final List<RepositoryFileTreeDto> children = getChildren(name);
    final String[] childrenArray = new String[children.size()];
    for (int i = 0; i < children.size(); i++) {
        final RepositoryFileTreeDto repositoryFileTreeDto = children.get(i);
        if (repositoryFileTreeDto == null) {
            continue;
        }//from w w w.j a  v  a  2s  . co  m

        final RepositoryFileDto file = repositoryFileTreeDto.getFile();
        if (file == null) {
            throw new FileSystemException(BI_SERVER_NULL_OBJECT);
        }
        childrenArray[i] = file.getName().replaceAll("\\%", "%25").replaceAll("\\!", "%21").replaceAll("\\+",
                "%2B");
    }
    return childrenArray;
}

From source file:org.pentaho.reporting.libraries.pensol.JCRSolutionFileModel.java

@Override
public boolean delete(FileName name) throws FileSystemException {

    boolean success = false;

    final RepositoryFileDto file = getFile(name);

    try {//from   w  ww .  j a v  a2 s  . c  o  m

        final WebResource resource = client.resource(url + DELETE_FILE_OR_FOLDER);
        final ClientResponse response = resource.put(ClientResponse.class, file.getId());

        if (response != null && response.getStatus() == Response.Status.OK.getStatusCode()) {
            refresh();
            success = true;
        } else {
            throw new FileSystemException("Failed with error-code " + response.getStatus());
        }

    } catch (Exception e) {
        throw new FileSystemException("Failed", e);
    }

    return success;
}