Package java.net

Examples of java.net.FileNameMap


     * @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

        }
        return null;
    }

    public static String getMimeType(String fileUrl) {
        FileNameMap fileNameMap = URLConnection.getFileNameMap();
        return fileNameMap.getContentTypeFor(fileUrl);
    }
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

    browser.setFocus();
  }
  // Insert a to-do checkbox
  @SuppressWarnings("unused")
  private void todoClicked() {
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String script_start = new String(
        "document.execCommand('insertHtml', false, '");
    String script_end = new String("');");
    String todo = new String(
        "<input TYPE=\"CHECKBOX\" value=\"false\" " +
View Full Code Here

  }
 
  // Handle URLs that are trying to be pasted
  public void handleUrls(QMimeData mime) {
    logger.log(logger.EXTREME, "Starting handleUrls");
    FileNameMap fileNameMap = URLConnection.getFileNameMap();

    List<QUrl> urlList = mime.urls();
    String url = new String();
    String script_start = new String(
        "document.execCommand('createLink', false, '");
    String script_end = new String("');");

    for (int i = 0; i < urlList.size(); i++) {
      url = urlList.get(i).toString();
      // Find out what type of file we have
      String mimeType = fileNameMap.getContentTypeFor(url);

      // If null returned, we need to guess at the file type
      if (mimeType == null)
        mimeType = "application/"
            + url.substring(url.lastIndexOf(".") + 1);
View Full Code Here

   * @param name    the name of a file
   * @return  a MIME type, or application/octet-stream if one can't be found
   */
  public static String getContentType(String name) {
    String contentType;
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    contentType = fileNameMap.getContentTypeFor(name);

    if (contentType == null) {
      int index = name.lastIndexOf(".");
      if (index > -1) {
        contentType = localFileNameMap.getProperty(name.substring(index));
View Full Code Here

    final String resource = u.getPath();
    return new URLConnection(u) {
      public void connect() {
      }
            public String getContentType() {
                FileNameMap fileNameMap = java.net.URLConnection.getFileNameMap();
                String contentType = fileNameMap.getContentTypeFor(resource);
                if (contentType == null)
                    contentType = "text/plain";
                return contentType;
            }
      public InputStream getInputStream() {
View Full Code Here

        if (!initializedHeaders || !exists) {
            length = file.length();
            lastModified = file.lastModified();

            if (!isDirectory) {
                FileNameMap map = java.net.URLConnection.getFileNameMap();
                contentType = map.getContentTypeFor(filename);
                if (contentType != null) {
                    properties.add(CONTENT_TYPE, contentType);
                }
                properties.add(CONTENT_LENGTH, String.valueOf(length));
View Full Code Here

        connect();

        if (is == null) {
            if (isDirectory) {
                FileNameMap map = java.net.URLConnection.getFileNameMap();

                StringBuffer buf = new StringBuffer();

                if (files == null) {
                    throw new FileNotFoundException(filename);
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.