Package net.sf.archimede.model.storedFile

Examples of net.sf.archimede.model.storedFile.StoredFile


        List files = this.oldFolder.getFiles();
        for (Iterator it = files.iterator(); it.hasNext(); ) {
            String filePath = (String) it.next();
            File file = new File(filePath);
           
            StoredFile storedFile = new StoredFileImpl();
            InputStream is = new FileInputStream(filePath);
            storedFile.setData(is);
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTimeInMillis(file.lastModified());
            storedFile.setLastModified(cal);
            storedFile.setMimeType( new MimetypesFileTypeMap().getContentType(file) );
            storedFile.setName(file.getName());
            storedFile.setParent(folder);
           
            if (storedFile.getReadUsers() == null) {
              storedFile.setReadUsers(new ArrayList());
            }
            storedFile.getReadUsers().add(new UserImpl("anonymous", ""));
           
            StoredFileDao.createInstance().save(storedFile);
            try {
        is.close();
      } catch (IOException e) {
View Full Code Here


            File currentFile = thesisFiles[i];
            System.out.println("Importing: " + currentFile.getPath());
            if (currentFile.isDirectory()) {
                continue;
            }
            StoredFile currentStoredFile = new StoredFileImpl();

            try {
               
                InputStream is = new FileInputStream(currentFile);
                try {
                    currentStoredFile.setData(is);
                    GregorianCalendar lastModified = new GregorianCalendar();
                    lastModified.setTimeInMillis(currentFile.lastModified());
                    currentStoredFile.setName(currentFile.getName());
                    currentStoredFile.setLastModified(lastModified);
                    currentStoredFile.setParent(thesisFolder);
                    currentStoredFile.setMimeType(new MimetypesFileTypeMap().getContentType(currentFile));
                    storedFiles.add(currentStoredFile);
                   
                    if (currentStoredFile.getReadUsers() == null) {
                        currentStoredFile.setReadUsers(new ArrayList());
                    }
                    currentStoredFile.getReadUsers().add(new UserImpl("anonymous", ""));
                   
                    StoredFileDao.createInstance().save(currentStoredFile);
                } finally {
                    is.close();
                }
View Full Code Here

            List storedFilesList = this.folder.getStoredFiles();
           
            //Look for "root" files names
            List rootFiles = new ArrayList();
            for (Iterator it = this.folder.getStoredFiles().iterator(); it.hasNext(); ) {
                StoredFile currentFile = (StoredFile) it.next();
                if (currentFile.getName().equals(this.folder.getName() + ".html") || currentFile.getName().equals(this.folder.getName() + ".pdf")) {
                    rootFiles.add(new ViewStoredFile(currentFile));
                }
            }
            if (rootFiles.size() > 0) {
                Collections.sort(rootFiles, new ContentSortComparator());
                this.storedFiles.setWrappedData(rootFiles);
                return this.storedFiles;
            }
           
            List viewStoredFilesList = new ArrayList(storedFilesList.size());
            for (Iterator it = storedFilesList.iterator(); it.hasNext(); ){
                StoredFile storedFile = (StoredFile) it.next();
                viewStoredFilesList.add(new ViewStoredFile(storedFile));
            }
            Collections.sort(viewStoredFilesList, new ContentSortComparator());
            this.storedFiles.setWrappedData(viewStoredFilesList);
        }
View Full Code Here

    }
   
    public void downloadFileAction(ActionEvent event) throws IOException {
       
        StoredFileDao fileDao = StoredFileDao.createInstance();
        StoredFile storedFile = (StoredFile) this.selectedFolder.getStoredFilesModel().getRowData();
        StoredFile file = fileDao.retrieve(storedFile.getId());
       
        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();     
        
        //text/plain, vnd.ms-excel, application/x-download, ...
        response.setContentType(file.getMimeType());
        response.setHeader("Content-disposition","attachment; filename=\"" + file.getName() + "\"");     
       
        ServletOutputStream out = null;
        InputStream stream = null;
        try {
            out = response.getOutputStream();
            stream = file.getData();
           
            int bytesRead = 0;
            byte[] buffer = new byte[8192];
            //Write to servlet output stream
            while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
View Full Code Here

    }
   
    public void downloadFileAction(ActionEvent event) throws IOException {
       
        StoredFileDao fileDao = StoredFileDao.createInstance();
        StoredFile storedFile = (StoredFile) this.selectedFolder.getStoredFilesModel().getRowData();
        StoredFile file2download = fileDao.retrieve(storedFile.getId());
       
        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();     
        
        //text/plain, vnd.ms-excel, application/x-download, ...
        response.setContentType(file2download.getMimeType());
        response.setHeader("Content-disposition","attachment; filename=\"" + file2download.getName() + "\"");     
       
        ServletOutputStream out = null;
        InputStream stream = null;
        try {
            out = response.getOutputStream();
            stream = file2download.getData();
           
            int bytesRead = 0;
            byte[] buffer = new byte[8192];
            //Write to servlet output stream
            while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
View Full Code Here

        this.file = file1;
    }

    public String submitUpload() throws IOException {
        if (this.file != null) {
            StoredFile newFile = new StoredFileImpl();
           
            //FIXME Mieux tester...
            String filename = new File(this.file.getName()).getName();
            newFile.setName(filename);
            newFile.setParent(this.selectedFolder.getFolder());
            InputStream data = null;
            try {
                data = this.file.getInputStream();
                newFile.setData(data);
                String contentType = this.file.getContentType();
                newFile.setMimeType(contentType);
                newFile.setLastModified(new GregorianCalendar());
                StoredFileDao.createInstance().save(newFile);
            } finally {
                if (data != null) {
                    data.close();
                }
View Full Code Here

    }
   
    public void downloadFileAction(ActionEvent event) throws IOException {
       
        StoredFileDao fileDao = StoredFileDao.createInstance();
        StoredFile storedFile = (StoredFile) this.selectedFolder.getStoredFilesModel().getRowData();
        StoredFile file2download = fileDao.retrieve(storedFile.getId());
       
        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();     
        
        //text/plain, vnd.ms-excel, application/x-download, ...
        response.setContentType(file2download.getMimeType());
        response.setHeader("Content-disposition","attachment; filename=\"" + file2download.getName() + "\"");     
       
        ServletOutputStream out = null;
        InputStream stream = null;
        try {
            out = response.getOutputStream();
            stream = file2download.getData();
           
            int bytesRead = 0;
            byte[] buffer = new byte[8192];
            //Write to servlet output stream
            while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
View Full Code Here

      // Format
      buffer.append(getXmlForElementName(rootElement, "dc:format"));
      // Identifier
      buffer.append(getXmlForElementName(rootElement, "dc:identifier"));
      // Archimede identifier
      StoredFile file = null;
      for (int i = 0; i < files.size(); i++) {
        file = (StoredFile) files.get(i);
        String url = baseUrl + "/" +"files"
            + "/" + folder.getId() + "/" + file.getName();

        // /files/#{exploration_folderBean.selectedFolder.id}/#{file.name}
        buffer.append("<dc:identifier>" + url + "</dc:identifier>");
      }
      // Source
View Full Code Here

    public boolean equals(Object object) {
        if (this == object) {
            return true;
        }
        if (object instanceof StoredFile) {
            StoredFile sf = (StoredFile) object;
            return this.getId().equals(sf.getId());
        }
        return false;
    }
View Full Code Here

            folder.setDatestamp(new GregorianCalendar());
            folderDao.save(folder);
            for (Iterator it = this.files.values().iterator(); it.hasNext();) {
                UploadedFile currentFile = (UploadedFile) it.next();
                List storedFiles = new ArrayList();
                StoredFile newFile = new StoredFileImpl();
                newFile.setName("content" + Math.random() + ".doc");
                newFile.setParent(folder);
                try {
                    newFile.setData(currentFile.getInputStream());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                newFile.setMimeType("application/msword");
                newFile.setLastModified(new GregorianCalendar());
                StoredFileDao.createInstance().save(newFile);
                storedFiles.add(newFile);
                folder.setStoredFiles(storedFiles);
            }
View Full Code Here

TOP

Related Classes of net.sf.archimede.model.storedFile.StoredFile

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.