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.reporting.libraries.pensol.JCRSolutionFileModel.java

private RepositoryFileDto getFile(FileName name) throws FileSystemException {

    if (name == null) {
        throw new FileSystemException(FILE_NOT_FOUND);
    }//from  w  w w .j ava 2s .co  m

    final String[] pathArray = computeFileNames(name);
    final RepositoryFileTreeDto fileInfo = lookupNode(pathArray);

    if (fileInfo == null) {
        throw new FileSystemException(FILE_NOT_FOUND, name);
    }

    final RepositoryFileDto file = fileInfo.getFile();

    if (file == null) {
        throw new FileSystemException(BI_SERVER_NULL_OBJECT);
    }
    return file;
}

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

protected void setDataInternally(final FileInfo fileInfo, final byte[] data) throws FileSystemException {
    throw new FileSystemException("Not implemented");
}

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

@Override
public boolean delete(FileName name) throws FileSystemException {
    throw new FileSystemException("Not implemented");
}

From source file:org.pentaho.reporting.libraries.pensol.vfs.LocalFileModel.java

/**
 * @noinspection ThrowCaughtLocally/*from  ww  w . j a  va 2  s .co m*/
 */
protected byte[] getDataInternally(final FileInfo fileInfo) throws FileSystemException {
    URI uri;
    String baseUrl = fileInfo.getUrl();
    try {
        URIBuilder builder = new URIBuilder(baseUrl);
        logger.debug("Connecting to '" + baseUrl + '\'');
        if (username != null) {
            builder.setParameter("userid", username);
        }
        if (password != null) {
            builder.setParameter("password", password);
        }
        uri = builder.build();
    } catch (URISyntaxException e) {
        throw new FileSystemException("Provided URL is invalid: " + baseUrl);
    }
    final HttpPost filePost = new HttpPost(uri);
    filePost.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");

    try {
        HttpResponse httpResponse = client.execute(filePost, context);
        final int lastStatus = httpResponse.getStatusLine().getStatusCode();
        if (lastStatus == HttpStatus.SC_UNAUTHORIZED) {
            throw new FileSystemException("401: User authentication failed.");
        } else if (lastStatus == HttpStatus.SC_NOT_FOUND) {
            throw new FileSystemException("404: Repository service not found on server.");
        } else if (lastStatus != HttpStatus.SC_OK) {
            throw new FileSystemException("Server error: HTTP lastStatus code " + lastStatus);
        }

        final InputStream postResult = httpResponse.getEntity().getContent();
        try {
            final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream();
            IOUtils.getInstance().copyStreams(postResult, bout);
            return bout.toByteArray();
        } finally {
            postResult.close();
        }
    } catch (FileSystemException ioe) {
        throw ioe;
    } catch (IOException ioe) {
        throw new FileSystemException("Failed", ioe);
    }
}

From source file:org.pentaho.reporting.libraries.pensol.vfs.LocalFileModel.java

public void createFolder(final FileName file) throws FileSystemException {
    final String[] fileName = computeFileNames(file);

    if (fileName.length < 2) {
        throw new FileSystemException("Cannot create directory in the root.");
    }/*from w  w  w.jav a2s  .  c o m*/

    final String[] parentPath = new String[fileName.length - 1];
    System.arraycopy(fileName, 0, parentPath, 0, parentPath.length);
    final FileInfo fileInfo = lookupNode(parentPath);
    if (fileInfo == null) {
        throw new FileSystemException("Cannot locate parent directory.");
    }

    try {
        final String solution = fileName[0];
        final String path = buildPath(fileName, 1, fileName.length - 1);
        final String name = fileName[fileName.length - 1];
        String description = getDescriptionEntries().get(file);
        if (description == null) {
            description = "";
        }
        final Configuration config = LibPensolBoot.getInstance().getGlobalConfig();
        final String urlMessage = config
                .getConfigProperty("org.pentaho.reporting.libraries.pensol.web.CreateNewFolder");
        final MessageFormat fmt = new MessageFormat(urlMessage);
        final String fullpath = fmt
                .format(new Object[] { URLEncoder.encode(solution, "UTF-8"), URLEncoder.encode(path, "UTF-8"),
                        URLEncoder.encode(name, "UTF-8"), URLEncoder.encode(description, "UTF-8") });

        URI uri;
        String baseUrl = url + fullpath;
        try {
            URIBuilder builder = new URIBuilder(baseUrl);
            logger.debug("Connecting to '" + baseUrl + '\'');
            if (username != null) {
                builder.setParameter("user", username);
            }
            if (password != null) {
                builder.setParameter("password", password);
            }
            uri = builder.build();
        } catch (URISyntaxException e) {
            throw new FileSystemException("Provided URL is invalid: " + baseUrl);
        }
        final HttpPost filePost = new HttpPost(uri);
        filePost.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");

        HttpResponse httpResponse = client.execute(filePost, context);
        final int lastStatus = httpResponse.getStatusLine().getStatusCode();
        if (lastStatus != HttpStatus.SC_OK) {
            throw new FileSystemException("Server error: HTTP status code " + lastStatus);
        }
        if (name == null) {
            throw new FileSystemException("Error creating folder: Empty name");
        }

        new FileInfo(fileInfo, name, description);
    } catch (FileSystemException fse) {
        throw fse;
    } catch (IOException ioe) {
        throw new FileSystemException("Failed", ioe);
    }
}

From source file:org.pentaho.reporting.libraries.pensol.vfs.LocalFileModel.java

protected void setDataInternally(final FileInfo fileInfo, final byte[] data) throws FileSystemException {
    throw new FileSystemException("Not supported");
}

From source file:org.pentaho.reporting.libraries.pensol.vfs.LocalFileModel.java

@Override
public boolean delete(FileName name) throws FileSystemException {
    throw new FileSystemException("Not supported");
}

From source file:org.pentaho.reporting.libraries.pensol.vfs.XmlSolutionFileModel.java

public boolean isDirectory(final FileName file) throws FileSystemException {
    final String[] fileName = computeFileNames(file);
    final FileInfo fileInfo = lookupNode(fileName);
    if (fileInfo == null) {
        throw new FileSystemException("File is not valid.");
    }//from   ww  w . ja  va 2s .  c  o  m
    return fileInfo.isDirectory();
}

From source file:org.pentaho.reporting.libraries.pensol.vfs.XmlSolutionFileModel.java

public boolean isVisible(final FileName file) throws FileSystemException {
    final String[] fileName = computeFileNames(file);
    final FileInfo fileInfo = lookupNode(fileName);
    if (fileInfo == null) {
        throw new FileSystemException("File is not valid.");
    }//from   ww w.  j a v  a  2s  .c  o m
    return fileInfo.isVisible();
}

From source file:org.pentaho.reporting.libraries.pensol.vfs.XmlSolutionFileModel.java

public String getName(final FileName file) throws FileSystemException {
    final String[] fileName = computeFileNames(file);
    final FileInfo fileInfo = lookupNode(fileName);
    if (fileInfo == null) {
        throw new FileSystemException("File is not valid.");
    }/*from   www. j a  v a 2  s  . com*/
    return fileInfo.getName();
}