Package java.net

Examples of java.net.FileNameMap


        String contentType = null;

        String name = fileContent.getFile().getName().getBaseName();
        if (name != null)
        {
            FileNameMap fileNameMap = URLConnection.getFileNameMap();
            contentType = fileNameMap.getContentTypeFor(name);
        }

        return new DefaultFileContentInfo(contentType, null);
    }
View Full Code Here


        response.addHeader("Cache-Control", "post-check=0, pre-check=0, false");
        response.setHeader("Pragma", "no-cache"); // HTTP/1.0
    }

    public static String getContentTypeByFileName(String fileName) {
        FileNameMap mime = URLConnection.getFileNameMap();
        return mime.getContentTypeFor(fileName);
    }
View Full Code Here

    public CommandResponse actionGoToStart(Panel panel, CommandRequest request) throws Exception {
        return new ShowPanelPage(panel, request, PAGE_SHOW);
    }

    public CommandResponse actionDownloadExport(final Panel panel, CommandRequest request) throws Exception {
        FileNameMap fileNameMap = URLConnection.getFileNameMap();
        final String contentType = fileNameMap.getContentTypeFor(panel.getParameterValue(RETURNED_FILE_NAME));

        final String disposition = "inline; filename=" + panel.getParameterValue(RETURNED_FILE_NAME) + ";";
        /*ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ZipOutputStream zos = new ZipOutputStream(bos);
        zos.putNextEntry(new ZipEntry(panel.getParameterValue(EXPORT_ENTRY_NAME) + "." + exportManager.getAllowedEntryExtensions()[0]));
View Full Code Here

    public CommandResponse actionGoToStart(Panel panel, CommandRequest request) throws Exception {
        return new ShowPanelPage(panel, request, PAGE_SHOW);
    }

    public CommandResponse actionDownloadExport(final Panel panel, CommandRequest request) throws Exception {
        FileNameMap fileNameMap = URLConnection.getFileNameMap();
        final String contentType = fileNameMap.getContentTypeFor(panel.getParameterValue(RETURNED_FILE_NAME));

        final String disposition = "inline; filename=" + panel.getParameterValue(RETURNED_FILE_NAME) + ";";
        /*ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ZipOutputStream zos = new ZipOutputStream(bos);
        zos.putNextEntry(new ZipEntry(panel.getParameterValue(EXPORT_ENTRY_NAME) + "." + exportManager.getAllowedEntryExtensions()[0]));
View Full Code Here

     * @tests java.net.URLConnection#getFileNameMap()
     */
    public void test_getFileNameMap() {
        // Tests for the standard MIME types -- users may override these
        // in their JRE
        FileNameMap map = URLConnection.getFileNameMap();

        // These types are defaulted
        assertEquals("text/html", map.getContentTypeFor(".htm"));
        assertEquals("text/html", map.getContentTypeFor(".html"));
        assertEquals("text/plain", map.getContentTypeFor(".text"));
        assertEquals("text/plain", map.getContentTypeFor(".txt"));

        // These types come from the properties file
        assertEquals("application/pdf", map.getContentTypeFor(".pdf"));
        assertEquals("application/zip", map.getContentTypeFor(".zip"));

        URLConnection.setFileNameMap(new FileNameMap() {
            public String getContentTypeFor(String fileName) {
                return "Spam!";
            }
        });
        try {
            assertEquals("Incorrect FileNameMap returned", "Spam!",
                    URLConnection.getFileNameMap().getContentTypeFor(null));
        } finally {
            // unset the map so other tests don't fail
            URLConnection.setFileNameMap(null);
        }
        // RI fails since it does not support fileName that does not begin with
        // '.'
        assertEquals("image/gif", map.getContentTypeFor("gif"));
    }
View Full Code Here

        String contentType = null;

        String name = fileContent.getFile().getName().getBaseName();
        if (name != null)
        {
            FileNameMap fileNameMap = URLConnection.getFileNameMap();
            contentType = fileNameMap.getContentTypeFor(name);
        }

        return new DefaultFileContentInfo(contentType, null);
    }
View Full Code Here

   * @tests java.net.URLConnection#getFileNameMap()
   */
  public void test_getFileNameMap() {
        // Tests for the standard MIME types -- users may override these
        // in their JRE
        FileNameMap map = URLConnection.getFileNameMap();
       
        // These types are defaulted
        assertEquals("text/html", map.getContentTypeFor(".htm"));
        assertEquals("text/html", map.getContentTypeFor(".html"));
        assertEquals("text/plain", map.getContentTypeFor(".text"));
        assertEquals("text/plain", map.getContentTypeFor(".txt"));
       
        // These types come from the properties file
        assertEquals("application/pdf", map.getContentTypeFor(".pdf"));
        assertEquals("application/zip", map.getContentTypeFor(".zip"));
       
    URLConnection.setFileNameMap(new FileNameMap() {
      public String getContentTypeFor(String fileName) {
        return "Spam!";
      }
    });
    try {
      assertEquals("Incorrect FileNameMap returned", "Spam!",
                    URLConnection.getFileNameMap().getContentTypeFor(null));
    } finally {
      // unset the map so other tests don't fail
      URLConnection.setFileNameMap(null);
    }
        // RI fails since it does not support fileName that does not begin with
        // '.'
        assertEquals("image/gif", map.getContentTypeFor("gif"));
  }
View Full Code Here

        response.addHeader("Cache-Control", "post-check=0, pre-check=0, false");
        response.setHeader("Pragma", "no-cache"); // HTTP/1.0
    }

    public static String getContentTypeByFileName(String fileName) {
        FileNameMap mime = URLConnection.getFileNameMap();
        return mime.getContentTypeFor(fileName);
    }
View Full Code Here

      throw new QQException(QQErrorCode.UNKNOWN_ERROR, e);
    }
  }
 
  private String getMimeType(File file){
     FileNameMap fileNameMap = URLConnection.getFileNameMap()
       return fileNameMap.getContentTypeFor(file.toString())
  }
View Full Code Here

        this.name = name;
    }

    public CommandResponse getResourceAsResponse() {
        SendStreamResponse response = new SendStreamResponse(new ByteArrayInputStream(array), "inline; filename=" + name + ";");
        FileNameMap fileNameMap = URLConnection.getFileNameMap();
        String contentType = fileNameMap.getContentTypeFor(name);
        if (contentType != null) response.setContentType(contentType);
        return response;
    }
View Full Code Here

TOP

Related Classes of java.net.FileNameMap

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.