Package org.apache.commons.vfs

Examples of org.apache.commons.vfs.FileContent


                throw new MessagingException("No output name available. Cannot output message!");
            }
            directory.close(); // remove any cached informations
            FileObject newFile = directory.resolveFile(name);
            newFile.close(); // remove any cached informations
            FileContent content = newFile.getContent();
            content.close();
            if (content != null) {
                out = content.getOutputStream();
            }
            if (out == null) {
                throw new MessagingException("No output stream available for output name: " + name);
            }
            marshaler.writeMessage(exchange, message, out, name);
View Full Code Here


      // as of version 3.7 we do not need to check anything other than that the version information is there
      // later we may have to add additional checks in here to filter out known broken versions.

      final String localPath = pathModel.getLocalPath();
      final FileObject object = fileSystemRoot.resolveFile(localPath);
      final FileContent content = object.getContent();
      final String majorVersionText = (String) fileSystem.getAttribute(WebSolutionFileSystem.MAJOR_VERSION);

      if (StringUtils.isEmpty(majorVersionText) == false)
      {
        final String paramService = (String) content.getAttribute("param-service-url");
        if (StringUtils.isEmpty(paramService))
        {
          return null;
        }
        if (paramService.startsWith("http://") || paramService.startsWith("https://"))
View Full Code Here

            try {
                logger.info(this + ".save()");
                FileInfo fileInfo = checkHook("PreSave", "save");
                FileObject file = fileInfo.getFile();
                checkForMigration(file.getParent());
                FileContent fileContent = file.getContent();
                if (hasContent()) IOUtil.copy(getContent().getInputStream(), true, fileContent.getOutputStream(), true);
                Iterator it = deletedAttributes.iterator();
                while (it.hasNext()) {
                    String name = (String) it.next();
                    if (fileContent.hasAttribute(name)) {
                        fileContent.removeAttribute(name);
                    } else {
                        fileContent.setAttribute(name, null);
                    }
                }
                Map defaultAttributes = fileInfo.getDefaultAttributes();
                it = attributes.entrySet().iterator();
                while (it.hasNext()) {
                    Map.Entry entry = (Map.Entry) it.next();
                    String name = (String) entry.getKey();
                    Object value = entry.getValue();
                    if (value.equals(defaultAttributes.get(name))) {
                        fileContent.removeAttribute(name);
                    } else {
                        fileContent.setAttribute(name, value);
                    }
                }
                refresh(fileInfo);
                hook("PostSave", fileInfo);
                clear();
View Full Code Here

      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(
View Full Code Here

                throw new MessagingException("No output name available. Cannot output message!");
            }
            directory.close(); // remove any cached informations
            FileObject newFile = directory.resolveFile(name);
            newFile.close(); // remove any cached informations
            FileContent content = newFile.getContent();
            content.close();
            if (content != null) {
                out = content.getOutputStream();
            }
            if (out == null) {
                throw new MessagingException("No output stream available for output name: " + name);
            }
            marshaler.writeMessage(exchange, message, out, name);
View Full Code Here

    protected void processFile(FileObject file) throws Exception {
        // SM-192: Force close the file, so that the cached informations are cleared
        file.close();
        String name = file.getName().getURI();
        FileContent content = file.getContent();
        content.close();
        InputStream in = content.getInputStream();
        if (in == null) {
            throw new JBIException("No input available for file!");
        }
        RobustInOnly exchange = getExchangeFactory().createRobustInOnlyExchange();
        NormalizedMessage message = exchange.createMessage();
        exchange.setInMessage(message);
        marshaler.readMessage(exchange, message, in, name);
        getDeliveryChannel().sendSync(exchange);
        in.close();
        content.close();
        if (exchange.getError() != null) {
            throw exchange.getError();
        }
    }
View Full Code Here

     */
    public void get(String srcVfsURI, File destination) throws IOException {
        VfsResource src = new VfsResource(srcVfsURI, getVFSManager());
        fireTransferInitiated(src, TransferEvent.REQUEST_GET);
        try {
            FileContent content = src.getContent();
            if (content == null) {
                throw new IllegalArgumentException("invalid vfs uri " + srcVfsURI
                        + ": no content found");
            }
            FileUtil.copy(content.getInputStream(), destination, progress);
        } catch (IOException ex) {
            fireTransferError(ex);
            throw ex;
        } catch (RuntimeException ex) {
            fireTransferError(ex);
View Full Code Here

    protected void renderFiles(List sortedChildren) throws FileSystemException {
        if (!sortedChildren.isEmpty()) {
            renderFragment("outputStart");
            for (int i = 0; i < sortedChildren.size(); i++) {
                FileObject fileObject = (FileObject) sortedChildren.get(i);
                FileContent content = fileObject.getContent();
                setAttribute("fileObject", fileObject);
                setAttribute("name", fileObject.getName().getBaseName());
                setAttribute("fileSize", content.getSize());
                String path = fileObject.getName().getPath();
                setAttribute("path", path);
                setAttribute("current", path.equals(getFileNavigationHandler().getCurrentFilePath()));
                String contentType = content.getContentInfo().getContentType();
                String extension = fileObject.getName().getExtension();
                if (contentType == null) {
                    contentType = extension;
                }
                setAttribute("contentType", contentType);
View Full Code Here

    StringBuffer buf = new StringBuffer(file.getName().getPath());
    try {
      if ( file.getType() == null || ! file.getType().hasContent() )
        return buf.toString();
     
      FileContent c = file.getContent();

      // Get standard attributes: Size, last modified
      if ( ! isDirectory(file)) {
        buf.append("\n" + VFSView.getResourceString("table.Size.title")
            + ": " + c. getSize());
        buf.append("\n"+ VFSView.getResourceString("table.Modified.title")
            + ": "  + VFSView.dateFormat.format(new Date(c.getLastModifiedTime())));
      }
     
      // Get custom attributes
      String[] attNames = c.getAttributeNames();
     
      for (int i = 0; i < attNames.length; i++) {
        buf.append("\n" + attNames[i] + ": " +  c.getAttribute(attNames[i]) );
      }
    } catch (FileSystemException e) {
      VFSView.debug(e);
    }
    return buf.toString();
View Full Code Here

TOP

Related Classes of org.apache.commons.vfs.FileContent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.