Example usage for org.apache.commons.httpclient Cookie isDomainAttributeSpecified

List of usage examples for org.apache.commons.httpclient Cookie isDomainAttributeSpecified

Introduction

In this page you can find the example usage for org.apache.commons.httpclient Cookie isDomainAttributeSpecified.

Prototype

public boolean isDomainAttributeSpecified() 

Source Link

Usage

From source file:com.cyberway.issue.crawler.fetcher.FetchHTTP.java

/**
 * Saves cookies to a file.// ww w  .  j a  v a2s.  c o  m
 *
 * Output file is in the Netscape 'cookies.txt' format.
 *
 * @param saveCookiesFile output file.
 */
public void saveCookies(String saveCookiesFile) {
    // Do nothing if cookiesFile is not specified.
    if (saveCookiesFile == null || saveCookiesFile.length() <= 0) {
        return;
    }

    FileOutputStream out = null;
    try {
        out = new FileOutputStream(new File(saveCookiesFile));
        @SuppressWarnings("unchecked")
        Map<String, Cookie> cookies = http.getState().getCookiesMap();
        String tab = "\t";
        out.write("# Heritrix Cookie File\n".getBytes());
        out.write("# This file is the Netscape cookies.txt format\n\n".getBytes());
        for (Cookie cookie : cookies.values()) {
            MutableString line = new MutableString(1024 * 2 /*Guess an initial size*/);
            line.append(cookie.getDomain());
            line.append(tab);
            line.append(cookie.isDomainAttributeSpecified() == true ? "TRUE" : "FALSE");
            line.append(tab);
            line.append(cookie.getPath());
            line.append(tab);
            line.append(cookie.getSecure() == true ? "TRUE" : "FALSE");
            line.append(tab);
            line.append(cookie.getName());
            line.append(tab);
            line.append((null == cookie.getValue()) ? "" : cookie.getValue());
            line.append("\n");
            out.write(line.toString().getBytes());
        }
    } catch (FileNotFoundException e) {
        // We should probably throw FatalConfigurationException.
        System.out.println("Could not find file: " + saveCookiesFile + " (Element: " + ATTR_SAVE_COOKIES + ")");
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.archive.crawler.fetcher.OptimizeFetchHTTP.java

/**
 * Saves cookies to a file./*  w ww  .j  a  va 2 s.  c  om*/
 *
 * Output file is in the Netscape 'cookies.txt' format.
 *
 * @param saveCookiesFile output file.
 */
public void saveCookies(String saveCookiesFile) {
    // Do nothing if cookiesFile is not specified.
    if (saveCookiesFile == null || saveCookiesFile.length() <= 0) {
        return;
    }

    FileOutputStream out = null;
    try {
        out = new FileOutputStream(new File(saveCookiesFile));
        @SuppressWarnings("unchecked")
        HttpClient http = this.getClient();
        Map<String, Cookie> cookies = http.getState().getCookiesMap();
        String tab = "\t";
        out.write("# Heritrix Cookie File\n".getBytes());
        out.write("# This file is the Netscape cookies.txt format\n\n".getBytes());
        for (Cookie cookie : cookies.values()) {
            MutableString line = new MutableString(1024 * 2 /*Guess an initial size*/);
            line.append(cookie.getDomain());
            line.append(tab);
            line.append(cookie.isDomainAttributeSpecified() == true ? "TRUE" : "FALSE");
            line.append(tab);
            line.append(cookie.getPath());
            line.append(tab);
            line.append(cookie.getSecure() == true ? "TRUE" : "FALSE");
            line.append(tab);
            line.append(cookie.getName());
            line.append(tab);
            line.append((null == cookie.getValue()) ? "" : cookie.getValue());
            line.append("\n");
            out.write(line.toString().getBytes());
        }
    } catch (FileNotFoundException e) {
        // We should probably throw FatalConfigurationException.
        System.out.println("Could not find file: " + saveCookiesFile + " (Element: " + ATTR_SAVE_COOKIES + ")");
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.archive.modules.fetcher.AbstractCookieStorage.java

public static void saveCookies(String saveCookiesFile, Map<String, Cookie> cookies) {
    // Do nothing if cookiesFile is not specified. 
    if (saveCookiesFile == null || saveCookiesFile.length() <= 0) {
        return;/*w  ww .  ja  v a 2s  .  co  m*/
    }

    FileOutputStream out = null;
    try {
        out = new FileOutputStream(new File(saveCookiesFile));
        String tab = "\t";
        out.write("# Heritrix Cookie File\n".getBytes());
        out.write("# This file is the Netscape cookies.txt format\n\n".getBytes());
        for (Cookie cookie : cookies.values()) {
            // Guess an initial size 
            MutableString line = new MutableString(1024 * 2);
            line.append(cookie.getDomain());
            line.append(tab);
            line.append(cookie.isDomainAttributeSpecified() ? "TRUE" : "FALSE");
            line.append(tab);
            line.append(cookie.getPath());
            line.append(tab);
            line.append(cookie.getSecure() ? "TRUE" : "FALSE");
            line.append(tab);
            line.append(cookie.getExpiryDate() != null ? cookie.getExpiryDate().getTime() / 1000 : -1);
            line.append(tab);
            line.append(cookie.getName());
            line.append(tab);
            line.append(cookie.getValue() != null ? cookie.getValue() : "");
            line.append("\n");
            out.write(line.toString().getBytes());
        }
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Unable to write " + saveCookiesFile, e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}