类org.apache.commons.httpclient.util.DateParseException源码实例Demo

下面列出了怎么用org.apache.commons.httpclient.util.DateParseException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: knopflerfish.org   文件: HttpClientConnection.java
public long getHeaderFieldDate(String key, long def) throws IOException {
  HttpMethod res = getResult(true);
  Header head = res.getResponseHeader(key);

  if (head == null) {
    return def;
  }

  try {
    Date date = DateUtil.parseDate(head.getValue());
    return date.getTime();

  } catch (DateParseException e) {
    return def;
  }
}
 
源代码2 项目: webarchive-commons   文件: ARC2WCDX.java
protected static void appendTimeField(StringBuilder builder, Object obj) {
    if(builder.length()>0) {
        // prepend with delimiter
        builder.append(' ');
    }
    if(obj==null) {
        builder.append("-");
        return;
    }
    if(obj instanceof Header) {
        String s = ((Header)obj).getValue().trim();
        try {
            Date date = DateUtil.parseDate(s);
            String d = ArchiveUtils.get14DigitDate(date);
            if(d.startsWith("209")) {
                d = "199"+d.substring(3);
            }
            obj = d;
        } catch (DateParseException e) {
            builder.append('e');
            return;
        }

    }
    builder.append(obj);
}
 
源代码3 项目: oneops   文件: Listener.java
private <T> long getTimeDiff(CmsWorkOrderSimpleBase<T> wo) throws DateParseException {
  String currentDate = formatDate(new Date(), SEARCH_TS_PATTERN);
  long currentTime = parseDate(currentDate, SEARCH_TS_FORMATS).getTime();
  long requestEnqueTime = parseDate(wo.getSearchTags().get(REQUEST_ENQUE_TS), SEARCH_TS_FORMATS)
      .getTime();
  return currentTime - requestEnqueTime;
}
 
源代码4 项目: knopflerfish.org   文件: HttpClientConnection.java
public long getDate() throws IOException {
  final HttpMethod res = getResult(true);
  final Header head = res.getResponseHeader("Date");

  if (head == null) {
    return 0;
  }

  try {
    return DateUtil.parseDate(head.getValue()).getTime();
  } catch (DateParseException e) {
    return 0;
  }
}
 
源代码5 项目: knopflerfish.org   文件: HttpClientConnection.java
public long getExpiration() throws IOException {
  HttpMethod res = getResult(true);
  Header head = res.getResponseHeader("Expires");

  if (head == null) {
    return 0;
  }

  try {
    return DateUtil.parseDate(head.getValue()).getTime();
  } catch (DateParseException e) {
    return 0;
  }
}
 
源代码6 项目: knopflerfish.org   文件: HttpClientConnection.java
public long getLastModified() throws IOException {
  HttpMethod res = getResult(true);
  Header head = res.getResponseHeader("Last-Modified");

  if (head != null) {
    try {
      return DateUtil.parseDate(head.getValue()).getTime();
    } catch (DateParseException e) {
      return 0;
    }
  }

  return 0;
}
 
源代码7 项目: zap-extensions   文件: CacheableScanRule.java
private Date parseDate(String dateStr) {
    Date newDate = null;
    try {
        newDate = DateUtil.parseDate(dateStr);
    } catch (DateParseException dpe) {
        // There was an error parsing the date, leave the var null
    }
    return newDate;
}
 
源代码8 项目: oneops   文件: AbstractOrderExecutor.java
private long getTimeElapsed(CmsWorkOrderSimpleBase wo) throws DateParseException {
  return System.currentTimeMillis() - DateUtil
      .parseDate(getSearchTag(wo, REQUEST_DEQUE_TS), SEARCH_TS_FORMATS).getTime();
}
 
源代码9 项目: knopflerfish.org   文件: CookieSpecBase.java
/**
  * Parse the cookie attribute and update the corresponsing {@link Cookie}
  * properties.
  *
  * @param attribute {@link HeaderElement} cookie attribute from the
  * <tt>Set- Cookie</tt>
  * @param cookie {@link Cookie} to be updated
  * @throws MalformedCookieException if an exception occurs during parsing
  */

public void parseAttribute(
    final NameValuePair attribute, final Cookie cookie)
    throws MalformedCookieException {
        
    if (attribute == null) {
        throw new IllegalArgumentException("Attribute may not be null.");
    }
    if (cookie == null) {
        throw new IllegalArgumentException("Cookie may not be null.");
    }
    final String paramName = attribute.getName().toLowerCase();
    String paramValue = attribute.getValue();

    if (paramName.equals("path")) {

        if ((paramValue == null) || (paramValue.trim().equals(""))) {
            paramValue = "/";
        }
        cookie.setPath(paramValue);
        cookie.setPathAttributeSpecified(true);

    } else if (paramName.equals("domain")) {

        if (paramValue == null) {
            throw new MalformedCookieException(
                "Missing value for domain attribute");
        }
        if (paramValue.trim().equals("")) {
            throw new MalformedCookieException(
                "Blank value for domain attribute");
        }
        cookie.setDomain(paramValue);
        cookie.setDomainAttributeSpecified(true);

    } else if (paramName.equals("max-age")) {

        if (paramValue == null) {
            throw new MalformedCookieException(
                "Missing value for max-age attribute");
        }
        int age;
        try {
            age = Integer.parseInt(paramValue);
        } catch (NumberFormatException e) {
            throw new MalformedCookieException ("Invalid max-age "
                + "attribute: " + e.getMessage());
        }
        cookie.setExpiryDate(
            new Date(System.currentTimeMillis() + age * 1000L));

    } else if (paramName.equals("secure")) {

        cookie.setSecure(true);

    } else if (paramName.equals("comment")) {

        cookie.setComment(paramValue);

    } else if (paramName.equals("expires")) {

        if (paramValue == null) {
            throw new MalformedCookieException(
                "Missing value for expires attribute");
        }

        try {
            cookie.setExpiryDate(DateUtil.parseDate(paramValue, this.datepatterns));
        } catch (DateParseException dpe) {
            LOG.debug("Error parsing cookie date", dpe);
            throw new MalformedCookieException(
                "Unable to parse expiration date parameter: " 
                + paramValue);
        }
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Unrecognized cookie attribute: " 
                + attribute.toString());
        }
    }
}
 
 类方法
 同包方法