Example usage for java.util Vector addAll

List of usage examples for java.util Vector addAll

Introduction

In this page you can find the example usage for java.util Vector addAll.

Prototype

public boolean addAll(Collection<? extends E> c) 

Source Link

Document

Appends all of the elements in the specified Collection to the end of this Vector, in the order that they are returned by the specified Collection's Iterator.

Usage

From source file:org.apache.cocoon.acting.AbstractValidatorAction.java

/**
 * Recursively resolve constraint sets that may "include" other constraint
 * sets and return a collection of all parameters to validate.
 * /*w w w  .  ja  v  a  2  s. c om*/
 * @param valsetstr
 * @param consets
 * @return collection of all parameters to validate
 */
protected Collection resolveConstraints(String valsetstr, Map consets) {
    /* get the list of params to be validated */
    Vector rules = new Vector();
    Configuration[] set = ((Configuration) consets.get(valsetstr)).getChildren("validate");
    for (int j = 0; j < set.length; j++) {
        rules.add(set[j]);
    }
    set = ((Configuration) consets.get(valsetstr)).getChildren("include");
    for (int j = 0; j < set.length; j++) {
        Collection tmp = resolveConstraints(set[j].getAttribute("name", ""), consets);
        rules.addAll(tmp);
    }
    return rules;
}

From source file:opendap.threddsHandler.ThreddsCatalogUtil.java

/**
 * Returns all of the THREDDS catalog URLs in the passed catalog element.
 * //www.  jav  a2 s  .  c  o m
 * @param catalogUrlString
 *            The URL from where the catalog was retrieved.
 * @param catalog
 *            The root element (the catalog element) in a THREDDS catalog
 *            document.
 * @param recurse
 *            If true the code will recursively descend into all of the
 *            child catalogs and return all the contained catalog URLs. Be
 *            Careful!
 * @return A vector of fully qualified URL Strings each of which points to a
 *         THREDDS catalog document.
 */
private Vector<String> getCatalogRefURLs(String catalogUrlString, Element catalog, boolean recurse)
        throws InterruptedException {

    Vector<String> catalogURLs = new Vector<String>();

    try {

        String href;
        String newCatalogURL;
        Element catalogRef;
        Iterator i = catalog.getDescendants(new ElementFilter("catalogRef", THREDDS.NS));
        while (i.hasNext()) {
            catalogRef = (Element) i.next();
            href = catalogRef.getAttributeValue("href", XLINK.NS);

            newCatalogURL = getCatalogURL(catalogUrlString, href);

            catalogURLs.add(newCatalogURL);

            if (recurse)
                catalogURLs.addAll(getCatalogRefURLs(newCatalogURL, recurse));

        }

    } catch (MalformedURLException e) {
        log.error("Malformed URL Exception: " + catalogUrlString + " msg: " + e.getMessage());
    }

    return catalogURLs;

}

From source file:net.rim.ejde.internal.ui.editors.locale.ResourceEditor.java

public IEditorReference[] getOpenEditorReferences() {
    Vector<IEditorReference> openEditorReferences = new Vector<IEditorReference>(0);
    IWorkbenchPage[] workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages();
    int workbenchPageCount = workbenchPage.length;

    for (int i = 0; i < workbenchPageCount; i++) {
        Collection<IEditorReference> editorReferences = Arrays.asList(workbenchPage[i].getEditorReferences());
        openEditorReferences.addAll(editorReferences);
    }//from w w  w  .  j  a  v  a2 s .  co  m

    return openEditorReferences.toArray(new IEditorReference[1]);
}

From source file:edu.ku.brc.specify.tasks.ExpressSearchTask.java

@Override
public java.util.List<NavBoxIFace> getNavBoxes() {
    initialize();/*from   ww  w.j  ava 2 s  .c o m*/

    Vector<NavBoxIFace> extendedNavBoxes = new Vector<NavBoxIFace>();

    extendedNavBoxes.clear();
    extendedNavBoxes.addAll(navBoxes);

    RecordSetTask rsTask = (RecordSetTask) ContextMgr.getTaskByClass(RecordSetTask.class);

    List<NavBoxIFace> nbs = rsTask.getNavBoxes();
    if (nbs != null) {
        extendedNavBoxes.addAll(nbs);
    }

    return extendedNavBoxes;
}

From source file:gda.scan.ScanDataPoint.java

/**
 * Just returns array of detector data.//from   ww w. java2  s  .  c om
 * 
 * @return all detector data.
 */
@Override
public Double[] getDetectorDataAsDoubles() {
    Vector<Double> vals = new Vector<Double>();
    if (getDetectorData() != null) {
        for (Object data : getDetectorData()) {
            PlottableDetectorData wrapper = (data instanceof PlottableDetectorData)
                    ? (PlottableDetectorData) data
                    : new DetectorDataWrapper(data);
            Double[] dvals = wrapper.getDoubleVals();
            vals.addAll(Arrays.asList(dvals));
        }
    }
    int expectedSize = getDetectorHeader().size();
    int actualSize = vals.size();
    if (actualSize != expectedSize) {
        throw new IllegalArgumentException("Detector data does not hold the expected number of fields actual:"
                + actualSize + " expected:" + expectedSize);
    }
    return vals.toArray(new Double[] {});
}

From source file:org.zaproxy.zap.extension.pscanrulesAlpha.CacheableScanner.java

@Override
public void scanHttpResponseReceive(HttpMessage msg, int id, Source source) {

    // TODO: standardise the logic in the case of duplicate / conflicting headers.
    try {/*from w ww  .j  a  v  a2s  .com*/
        if (logger.isDebugEnabled())
            logger.debug("Checking URL " + msg.getRequestHeader().getURI().getURI() + " for storability");

        // storability: is the request method understood by the cache and defined as being
        // cacheable?
        String method = msg.getRequestHeader().getMethod();
        String methodUpper = method.toUpperCase();
        if (!(methodUpper.equals(HttpRequestHeader.GET) || methodUpper.equals(HttpRequestHeader.HEAD)
                || methodUpper.equals(HttpRequestHeader.POST))) {
            // non-cacheable method ==> non-storable
            if (logger.isDebugEnabled())
                logger.debug(msg.getRequestHeader().getURI().getURI()
                        + " is not storable due to the use of the non-cacheable request method '" + method
                        + "'");
            alertNonStorable(msg, id, method + " ");
            return;
        }

        // is the response status code "understood" by the cache?
        // this is somewhat implementation specific, so lets assume that a cache "understands"
        // all 1XX, 2XX, 3XX, 4XX, and 5XX response classes for now.
        // this logic will allow us to detect if the response is storable by "some" compliant
        // caching server
        int responseClass = msg.getResponseHeader().getStatusCode() / 100;
        if ((responseClass != 1) && (responseClass != 2) && (responseClass != 3) && (responseClass != 4)
                && (responseClass != 5)) {
            if (logger.isDebugEnabled())
                logger.debug(msg.getRequestHeader().getURI().getURI()
                        + " is not storable due to the use of a HTTP response class [" + responseClass
                        + "] that we do not 'understand' (we 'understand' 1XX, 2XX, 3XX, 4XX, and 5XX response classes)");
            alertNonStorable(msg, id, String.valueOf(msg.getResponseHeader().getStatusCode()));
            return;
        }

        // does the "no-store" cache directive appear in request or response header fields?
        // 1: check the Pragma request header (for HTTP 1.0 caches)
        // 2: check the Pragma response header (for HTTP 1.0 caches)
        // 3: check the Cache-Control request header (for HTTP 1.1 caches)
        // 4: check the Cache-Control response header (for HTTP 1.1 caches)
        Vector<String> headers = new Vector<String>();
        Vector<String> temp = msg.getRequestHeader().getHeaders(HttpHeader.PRAGMA);
        if (temp != null)
            headers.addAll(temp);
        temp = msg.getResponseHeader().getHeaders(HttpHeader.PRAGMA);
        if (temp != null)
            headers.addAll(temp);
        temp = msg.getRequestHeader().getHeaders(HttpHeader.CACHE_CONTROL);
        if (temp != null)
            headers.addAll(temp);
        temp = msg.getResponseHeader().getHeaders(HttpHeader.CACHE_CONTROL);
        if (temp != null)
            headers.addAll(temp);

        for (String directive : headers) {
            for (String directiveToken : directive.split(" ")) {
                // strip off any trailing comma
                if (directiveToken.endsWith(","))
                    directiveToken = directiveToken.substring(0, directiveToken.length() - 1);
                if (logger.isTraceEnabled())
                    logger.trace("Looking for 'no-store' in [" + directiveToken + "]");
                if (directiveToken.toLowerCase().equals("no-store")) {
                    if (logger.isDebugEnabled())
                        logger.debug(msg.getRequestHeader().getURI().getURI()
                                + " is not storable due to the use of HTTP caching directive 'no-store' in the request or response");
                    alertNonStorable(msg, id, directiveToken);
                    return;
                }
            }
        }

        // does the "private" response directive appear in the response, if the cache is shared
        // check the Cache-Control response header only (for HTTP 1.1 caches)
        Vector<String> responseHeadersCacheControl = msg.getResponseHeader()
                .getHeaders(HttpHeader.CACHE_CONTROL);
        if (responseHeadersCacheControl != null) {
            for (String directive : responseHeadersCacheControl) {
                for (String directiveToken : directive.split(" ")) {
                    // strip off any trailing comma
                    if (directiveToken.endsWith(","))
                        directiveToken = directiveToken.substring(0, directiveToken.length() - 1);
                    if (logger.isTraceEnabled())
                        logger.trace("Looking for 'private' in [" + directiveToken + "]");
                    if (directiveToken.toLowerCase().equals("private")) {
                        if (logger.isDebugEnabled())
                            logger.debug(msg.getRequestHeader().getURI().getURI()
                                    + " is not storable due to the use of HTTP caching directive 'private' in the response");
                        alertNonStorable(msg, id, directiveToken);
                        return;
                    }
                }
            }
        }

        // does the Authorization header field appear in the request, if the cache is shared
        // (which we assume it is for now)
        // if so, does the response explicitly allow it to be cached? (see rfc7234 section 3.2)
        // Note: this logic defines if an initial request is storable.  A second request for the
        // same URL
        // may or may not be actually served from the cache, depending on other criteria, such
        // as whether the cached response is
        // considered stale (based on the values of s-maxage and other values).  This is in
        // accordance with rfc7234 section 3.2.
        Vector<String> authHeaders = msg.getRequestHeader().getHeaders(HttpHeader.AUTHORIZATION);
        if (authHeaders != null) {
            // there is an authorization header
            // look for "must-revalidate", "public", and "s-maxage", in the response, since
            // these permit
            // a request with an "Authorization" request header to be cached
            if (responseHeadersCacheControl != null) {
                boolean authorizedIsStorable = false;
                for (String directive : responseHeadersCacheControl) {
                    for (String directiveToken : directive.split(" ")) {
                        // strip off any trailing comma
                        if (directiveToken.endsWith(","))
                            directiveToken = directiveToken.substring(0, directiveToken.length() - 1);
                        if (logger.isTraceEnabled())
                            logger.trace("Looking for 'must-revalidate', 'public', 's-maxage' in ["
                                    + directiveToken + "]");
                        if ((directiveToken.toLowerCase().equals("must-revalidate"))
                                || (directiveToken.toLowerCase().equals("public"))
                                || (directiveToken.toLowerCase().startsWith("s-maxage="))) {
                            authorizedIsStorable = true;
                            break;
                        }
                    }
                }
                // is the request with an authorisation header allowed, based on the response
                // headers?
                if (!authorizedIsStorable) {
                    if (logger.isDebugEnabled())
                        logger.debug(msg.getRequestHeader().getURI().getURI()
                                + " is not storable due to the use of the 'Authorisation' request header, without a compensatory 'must-revalidate', 'public', or 's-maxage' directive in the response");
                    alertNonStorable(msg, id, HttpHeader.AUTHORIZATION + ":");
                    return;
                }
            } else {
                if (logger.isDebugEnabled())
                    logger.debug(msg.getRequestHeader().getURI().getURI()
                            + " is not storable due to the use of the 'Authorisation' request header, without a compensatory 'must-revalidate', 'public', or 's-maxage' directive in the response (no 'Cache-Control' directive was noted)");
                alertNonStorable(msg, id, HttpHeader.AUTHORIZATION + ":");
                return;
            }
        }

        // in addition to the checks above, just one of the following needs to be true for the
        // response to be storable
        /*
        * the response
        *  contains an Expires header field (see Section 5.3), or
        *  contains a max-age response directive (see Section 5.2.2.8), or
        *  contains a s-maxage response directive (see Section 5.2.2.9)
           and the cache is shared, or
        *  contains a Cache Control Extension (see Section 5.2.3) that
           allows it to be cached, or
        *  has a status code that is defined as cacheable by default (see
           Section 4.2.2), or
        *  contains a public response directive (see Section 5.2.2.5).
        */
        // TODO: replace "Expires" with some defined constant. Can't find one right now though.
        // Ho Hum.
        Vector<String> expires = msg.getResponseHeader().getHeaders("Expires");
        if (expires != null)
            if (logger.isDebugEnabled())
                logger.debug(msg.getRequestHeader().getURI().getURI()
                        + " *is* storable due to the basic checks, and the presence of the 'Expires' header in the response");
        // grab this for later. Not needed for "storability" checks.
        Vector<String> dates = msg.getResponseHeader().getHeaders("Date");

        String maxAge = null, sMaxAge = null, publicDirective = null;
        if (responseHeadersCacheControl != null) {
            for (String directive : responseHeadersCacheControl) {
                for (String directiveToken : directive.split(" ")) {
                    // strip off any trailing comma
                    if (directiveToken.endsWith(","))
                        directiveToken = directiveToken.substring(0, directiveToken.length() - 1);
                    if (logger.isTraceEnabled())
                        logger.trace("Looking for 'max-age', 's-maxage', 'public' in [" + directiveToken + "]");
                    if (directiveToken.toLowerCase().startsWith("max-age=")) {
                        if (logger.isDebugEnabled())
                            logger.debug(msg.getRequestHeader().getURI().getURI()
                                    + " *is* storable due to the basic checks, and the presence of the 'max-age' caching directive in the response");
                        maxAge = directiveToken;
                    }
                    if (directiveToken.toLowerCase().startsWith("s-maxage=")) { // for a shared cache..
                        if (logger.isDebugEnabled())
                            logger.debug(msg.getRequestHeader().getURI().getURI()
                                    + " *is* storable due to the basic checks, and the presence of the 's-maxage' caching directive in the response");
                        sMaxAge = directiveToken;
                    }
                    if (directiveToken.toLowerCase().equals("public")) {
                        if (logger.isDebugEnabled())
                            logger.debug(msg.getRequestHeader().getURI().getURI()
                                    + " *is* storable due to the basic checks, and the presence of the 'public' caching directive in the response");
                        publicDirective = directiveToken;
                    }
                }
            }
        }
        // TODO: implement checks here for known (implementation specific) Cache Control
        // Extensions that would
        // allow the response to be cached.

        // rfc7231 defines the following response codes as cacheable by default
        boolean statusCodeCacheable = false;
        int response = msg.getResponseHeader().getStatusCode();
        if ((response == 200) || (response == 203) || (response == 204) || (response == 206)
                || (response == 300) || (response == 301) || (response == 404) || (response == 405)
                || (response == 410) || (response == 414) || (response == 501)) {
            statusCodeCacheable = true;
            if (logger.isDebugEnabled())
                logger.debug(msg.getRequestHeader().getURI().getURI()
                        + " *is* storable due to the basic checks, and the presence of a cacheable response status code (200, 203, 204, 206, 300, 301, 404, 405, 410, 414, 501)");
        }

        if (expires == null && maxAge == null && sMaxAge == null && statusCodeCacheable == false
                && publicDirective == null) {
            if (logger.isDebugEnabled())
                logger.debug(msg.getRequestHeader().getURI().getURI()
                        + " is not storable due to the absence of any of an 'Expires' header, 'max-age' directive, 's-maxage' directive, 'public' directive, or cacheable response status code (200, 203, 204, 206, 300, 301, 404, 405, 410, 414, 501) in the response");
            // we raise the alert with the status code as evidence, because all the other
            // conditions are "absent", rather "present" (ie, it is the only possible evidence
            // we can show in this case).
            alertNonStorable(msg, id, String.valueOf(response));
            return;
        }

        // at this point, we *know* that the response is storable.
        // so check if the content is retrievable from the cache (ie "cacheable")
        /*
         *   When presented with a request, a cache MUST NOT reuse a stored
         *   response, unless:
         *   o  The presented effective request URI (Section 5.5 of [RFC7230]) and
         *      that of the stored response match, and
         *   o  the request method associated with the stored response allows it
         *      to be used for the presented request, and
         *   o  selecting header fields nominated by the stored response (if any)
         *      match those presented (see Section 4.1), and
         *   o  the presented request does not contain the no-cache pragma
         *      (Section 5.4), nor the no-cache cache directive (Section 5.2.1),
         *      unless the stored response is successfully validated
         *      (Section 4.3), and
         *   o  the stored response does not contain the no-cache cache directive
         *      (Section 5.2.2.2), unless it is successfully validated
         *      (Section 4.3), and
         *   o  the stored response is either:
         *      *  fresh (see Section 4.2), or
         *      *  allowed to be served stale (see Section 4.2.4), or
         *      *  successfully validated (see Section 4.3).
         *   Note that any of the requirements listed above can be overridden by a
         *   cache-control extension; see Section 5.2.3.
         */

        // 1: we assume that the presented effective request URI matches that of the stored
        // response in the cache
        // 2: we assume that the presented request method is compatible with the request method
        // of the stored response
        // 3: we assume that the presented selecting header fields match the selecting header
        // fields nominated by the stored response (if any)
        // 4: we assume that the presented request does not contain the no-cache pragma, nor the
        // no-cache cache directive

        // check if the stored response does not contain the no-cache cache directive, unless it
        // is successfully validated
        // note: we cannot (passively or actively) check the re-validation process, and can only
        // assume that it will properly
        // respond with details of whether the cache server can serve the cached contents or
        // not.  In any event, this decision is made by the origin
        // server, and is not at the discretion of the cache server, so we do not concern
        // ourselves with it here.
        headers = msg.getResponseHeader().getHeaders(HttpHeader.CACHE_CONTROL);
        if (headers != null) {
            for (String directive : headers) {
                for (String directiveToken : directive.split(" ")) {
                    // strip off any trailing comma
                    if (directiveToken.endsWith(","))
                        directiveToken = directiveToken.substring(0, directiveToken.length() - 1);
                    if (logger.isTraceEnabled())
                        logger.trace("Looking for 'no-cache' in [" + directiveToken + "]");
                    // Note: if the directive looked like "Cache-Control: no-cache #field-name"
                    // (with the optional field name argument, with no comma separating them),
                    // then the "no-cache" directive only applies to the field name (response
                    // header) in question, and not the entire contents.
                    // In this case, the remainder of the contents may be served without
                    // validation.  The logic below is consistent with this requirement.
                    if (directiveToken.toLowerCase().equals("no-cache")) {
                        if (logger.isDebugEnabled())
                            logger.debug(msg.getRequestHeader().getURI().getURI()
                                    + " is not retrievable from the cache (cacheable) due to the use of the unqualified HTTP caching directive 'no-cache' in the response");
                        alertStorableNonCacheable(msg, id, directiveToken);
                        return;
                    }
                }
            }
        }

        // is the stored response fresh?
        // Note that fresh = freshness lifetime > current age
        long lifetime = -1;
        boolean lifetimeFound = false;
        String freshEvidence = null;
        String otherInfo = null;

        // 1: calculate the freshness lifetime of the request, using the following checks, with
        // the following priority, as specified by rfc7234.
        //   1a:Get the "s-maxage" response directive value (if duplicates exist, the values are
        // invalid)
        if (responseHeadersCacheControl != null) {
            int lifetimesFound = 0;
            for (String directive : responseHeadersCacheControl) {
                for (String directiveToken : directive.split(" ")) {
                    // strip off any trailing comma
                    if (directiveToken.endsWith(","))
                        directiveToken = directiveToken.substring(0, directiveToken.length() - 1);
                    if (logger.isTraceEnabled())
                        logger.trace("Looking for 's-maxage' in [" + directiveToken + "]");
                    if (directiveToken.toLowerCase().startsWith("s-maxage=")) {
                        if (logger.isDebugEnabled())
                            logger.debug(msg.getRequestHeader().getURI().getURI()
                                    + " has a caching lifetime defined by an HTTP caching directive 's-maxage' ");
                        lifetimeFound = true;
                        lifetimesFound++;
                        // get the portion of the string after "s-maxage="
                        lifetime = Long.parseLong(directiveToken.substring("s-maxage=".length()));
                        freshEvidence = directiveToken;
                    }
                }
            }
            // if duplicates exist, the values are invalid. as per rfc7234.
            if (lifetimesFound > 1) {
                lifetimeFound = false;
                lifetime = -1;
                freshEvidence = null;
                if (logger.isDebugEnabled())
                    logger.debug(msg.getRequestHeader().getURI().getURI()
                            + " had multiple caching lifetimes defined by an HTTP caching directive 's-maxage'. Invalidating all of these!");
            }
        }

        //   1b:Get the "max-age" response directive value (if duplicates exist, the values are
        // invalid)
        if (!lifetimeFound) {
            if (responseHeadersCacheControl != null) {
                int lifetimesFound = 0;
                for (String directive : responseHeadersCacheControl) {
                    for (String directiveToken : directive.split(" ")) {
                        // strip off any trailing comma
                        if (directiveToken.endsWith(","))
                            directiveToken = directiveToken.substring(0, directiveToken.length() - 1);
                        if (logger.isTraceEnabled())
                            logger.trace("Looking for 'max-age' in [" + directiveToken + "]");
                        if (directiveToken.toLowerCase().startsWith("max-age=")) {
                            if (logger.isDebugEnabled())
                                logger.debug(msg.getRequestHeader().getURI().getURI()
                                        + " has a caching lifetime defined by an HTTP caching directive 'max-age' ");
                            lifetimeFound = true;
                            lifetimesFound++;
                            // get the portion of the string after "maxage="
                            // Split on comma and use 0th item in case there weren't spaces:
                            // Cache-Control: max-age=7776000,private
                            try {
                                lifetime = Long
                                        .parseLong(directiveToken.split(",")[0].substring("max-age=".length()));
                            } catch (NumberFormatException nfe) {
                                lifetimeFound = false;
                                lifetimesFound--;
                                if (logger.isDebugEnabled()) {
                                    logger.debug(
                                            "Could not parse max-age to establish lifetime. Perhaps the value exceeds Long.MAX_VALUE or contains non-number characters:"
                                                    + directiveToken);
                                }
                            }
                            freshEvidence = directiveToken;
                        }
                    }
                }
                // if duplicates exist, the values are invalid. as per rfc7234.
                if (lifetimesFound > 1) {
                    lifetimeFound = false;
                    lifetime = -1;
                    freshEvidence = null;
                    if (logger.isDebugEnabled())
                        logger.debug(msg.getRequestHeader().getURI().getURI()
                                + " had multiple caching lifetimes defined by an HTTP caching directive 'max-age'. Invalidating all of these!");
                }
            }
        }

        //   1c: Get the "Expires" response header value - "Date" response header field. ("Date"
        // is optional if the origin has no clock, or returned a 1XX or 5XX response, else
        // mandatory)
        if (!lifetimeFound) {
            String expiresHeader = null;
            String dateHeader = null;
            if (expires != null) {
                // Expires can be absent, or take the form of "Thu, 27 Nov 2014 12:21:57 GMT",
                // "-1", "0", etc.
                // Invalid dates are treated as "expired"
                int expiresHeadersFound = 0;
                for (String directive : expires) {
                    if (logger.isDebugEnabled())
                        logger.debug(msg.getRequestHeader().getURI().getURI()
                                + " has a caching lifetime expiry defined by an HTTP response header 'Expires'");
                    expiresHeadersFound++;
                    expiresHeader = directive;
                    freshEvidence = directive;
                }
                // if duplicates exist, the values are invalid. as per rfc7234.
                if (expiresHeadersFound > 1) {
                    expiresHeader = null;
                    if (logger.isDebugEnabled())
                        logger.debug(msg.getRequestHeader().getURI().getURI()
                                + " had multiple caching lifetime expirys defined by an HTTP response header 'Expires'. Invalidating all of these!");
                } else {
                    // we now have a single "expiry".
                    // Now it is time to get the "date" for the request, so we can subtract the
                    // "date" from the "expiry" to get the "lifetime".
                    if (dates != null) {
                        int dateHeadersFound = 0;
                        for (String directive : dates) {
                            if (logger.isDebugEnabled())
                                logger.debug(msg.getRequestHeader().getURI().getURI()
                                        + " has a caching lifetime date defined by an HTTP response header 'Date'");
                            dateHeadersFound++;
                            dateHeader = directive;
                        }
                        // if duplicates exist, the values are invalid. as per rfc7234.
                        if (dateHeadersFound > 1) {
                            dateHeader = null;
                            if (logger.isDebugEnabled())
                                logger.debug(msg.getRequestHeader().getURI().getURI()
                                        + " had multiple caching lifetime dates defined by an HTTP response header 'Date'. Invalidating all of these!");
                        } else {
                            // we have one expiry, and one date. Yippee.. Are they valid tough??
                            // both dates can be invalid, or have one of 3 formats, all of which
                            // MUST be supported!
                            Date expiresDate = parseDate(expiresHeader);

                            if (expiresDate != null) {
                                Date dateDate = parseDate(dateHeader);
                                if (dateDate != null) {
                                    // calculate the lifetime = Expires - Date
                                    lifetimeFound = true;
                                    lifetime = (expiresDate.getTime() - dateDate.getTime()) / 1000;
                                    // there is multiple parts to the evidence in this case (the
                                    // Expiry, and the Date, but lets show the Expiry)
                                    freshEvidence = expiresHeader;
                                    if (logger.isDebugEnabled())
                                        logger.debug(msg.getRequestHeader().getURI().getURI()
                                                + " had an 'Expires' date and a 'Date' date, which were used to calculate the lifetime of the request");
                                } else {
                                    // the "Date" date is not valid. Treat it as "expired"
                                    if (logger.isDebugEnabled())
                                        logger.debug(msg.getRequestHeader().getURI().getURI()
                                                + " had an invalid caching lifetime date defined by an HTTP response header 'Date'. Ignoring the 'Expires' header for the purposes of lifetime calculation.");
                                    lifetime = -1;
                                }
                            } else {
                                // the expires date is not valid. Treat it as "expired"
                                // (will not result in a "cacheable" alert, so the evidence is
                                // not needed, in fact
                                if (logger.isDebugEnabled())
                                    logger.debug(msg.getRequestHeader().getURI().getURI()
                                            + " had an invalid caching lifetime expiry date defined by an HTTP response header 'Expiry'. Assuming an historic/ expired lifetime.");
                                lifetimeFound = true;
                                lifetime = 0;
                                freshEvidence = expiresHeader;
                            }
                        }
                    } else {
                        // "Dates" is not defined. Nothing to do!
                        if (logger.isDebugEnabled())
                            logger.debug(msg.getRequestHeader().getURI().getURI()
                                    + " has a caching lifetime expiry defined by an HTTP response header 'Expires', but no 'Date' header to subtract from it");
                    }
                }
            } else {
                // "Expires" is not defined. Nothing to do!
                if (logger.isDebugEnabled())
                    logger.debug(msg.getRequestHeader().getURI().getURI()
                            + " has no caching lifetime expiry defined by an HTTP response header 'Expires'");
            }
        }

        //   1d: Use a heuristic to determine a "plausible" expiration time.  This is
        // implementation specific, and the implementation is permitted to be liberal.
        //  for the purposes of this exercise, lets assume the cache chooses a "plausible"
        // expiration of 1 year (expressed in seconds)
        if (!lifetimeFound) {
            if (logger.isDebugEnabled())
                logger.debug(msg.getRequestHeader().getURI().getURI()
                        + " has no caching lifetime expiry of any form, so assuming that it is set 'heuristically' to 1 year (as a form of worst case)");
            lifetimeFound = true;
            lifetime = 60 * 60 * 24 * 365;
            // a liberal heuristic was assumed, for which no actual evidence exists
            freshEvidence = null;
            otherInfo = Constant.messages
                    .getString(MESSAGE_PREFIX_STORABLE_CACHEABLE + "otherinfo.liberallifetimeheuristic");
        }

        if (logger.isDebugEnabled())
            logger.debug(msg.getRequestHeader().getURI().getURI() + " has a caching lifetime of " + lifetime);

        // 2: calculate the current age of the request
        //   Note that since we are not necessarily testing via a cache, the "Age" header may
        // not be set (this is set by the caching server, not by the web server)
        //   so we can only possibly get the "apparent_age", and not the "corrected_age_value"
        // documented in rfc7234.
        //   In any event, this is not an issue, because in the worst case, the user could be
        // sending the first request for a given URL, placing
        //   the response in the cache, with an age approaching 0 (depending on network delay).
        //   By this logic, let's not even try to check the "apparent_age" (since it depends on
        // our network, and could be completely different for other users)
        //   and let's assume that in at least some cases, the "age" can be 0 (the most extreme
        // case, from the point of view of "freshness").
        //   so "freshness" depends purely on the defined lifetime, in practice.
        long age = 0;

        // so after all that, is the response fresh or not?
        if (lifetime > age) {
            // fresh, so it can be retrieved from the cache
            if (logger.isDebugEnabled())
                logger.debug(msg.getRequestHeader().getURI().getURI()
                        + " is retrievable from the cache (cacheable), since it is fresh");
            alertStorableCacheable(msg, id, freshEvidence, otherInfo);
            return;
        } else {
            // stale!
            // is the stored response allowed to be served stale?
            // if the following are not present, the response *can* be served stale..
            // Note: this area of the RFC is vague at best (and somewhat contradictory), so this
            // area may need to be reviewed once the RFC has been updated
            // (the version used is rfc7234 from June 2014)
            /*
            "must-revalidate"    - OK (fairly explicit)
            "proxy-revalidate"   - OK (fairly explicit)
            "s-maxage"         - see rfc7234, section 3.2
            "max-age"         - inferred, based on the case for "s-maxage"
            */

            boolean staleRetrieveAllowed = true;
            String doNotRetrieveStaleEvidence = null;
            if (responseHeadersCacheControl != null) {
                for (String directive : responseHeadersCacheControl) {
                    for (String directiveToken : directive.split(" ")) {
                        // strip off any trailing comma
                        if (directiveToken.endsWith(","))
                            directiveToken = directiveToken.substring(0, directiveToken.length() - 1);
                        if (logger.isTraceEnabled())
                            logger.trace(
                                    "Looking for 'must-revalidate', 'proxy-revalidate', 's-maxage', 'max-age' in ["
                                            + directiveToken + "]");
                        if ((directiveToken.toLowerCase().equals("must-revalidate"))
                                || (directiveToken.toLowerCase().equals("proxy-revalidate"))
                                || (directiveToken.toLowerCase().startsWith("s-maxage="))
                                || (directiveToken.toLowerCase().startsWith("max-age="))) {
                            staleRetrieveAllowed = false;
                            doNotRetrieveStaleEvidence = directiveToken;
                            break;
                        }
                    }
                }
            }
            // TODO: check for any known Cache Control Extensions here, before making a final
            // call on the retrievability of the cached data.
            if (staleRetrieveAllowed) {
                // no directives were configured to prevent stale responses being retrieved
                // (without validation)
                alertStorableCacheable(msg, id, "", Constant.messages
                        .getString(MESSAGE_PREFIX_STORABLE_CACHEABLE + "otherinfo.staleretrievenotblocked"));
            } else {
                // the directives do not allow stale responses to be retrieved
                // we saw just one other scenario where this could happen: where the response
                // was cached, but the "no-cache" response directive was specified
                alertStorableNonCacheable(msg, id, doNotRetrieveStaleEvidence);
            }
        }
    } catch (Exception e) {
        logger.error("An error occurred while checking a URI [ " + msg.getRequestHeader().getURI().toString()
                + " ] for cacheability", e);
    }
}

From source file:skoa.helpers.ConfiguracionGraficas.java

private void vistaIntermedia4() {
    vacia = true; //Una vez llegado aqu, ya se empieza a llenar la carpeta destino.
    for (int i = 0; i < datos.getComponentCount(); i++)
        datos.remove(i); //Borra 
    datos.removeAll();//from w w w  . j  a  v  a2 s. co  m
    JPanel p = new JPanel();
    p.setLayout(new GridLayout(3, 1));
    //JLabel l=new JLabel(" Grfica "+ng+":  "+"Direcciones: "+seleccionadas);
    //l.setFont(new Font("Tahoma",Font.BOLD,12));
    p2 = new JPanel();
    p2.setLayout(new GridLayout(1, 3));
    l = new JLabel(" Grfica " + ng + ":  " + "Direcciones: ");
    l.setFont(new Font("Tahoma", Font.BOLD, 12));
    p2.add(l);
    Vector<String> AuxSeleccionadas = new Vector<String>();
    AuxSeleccionadas.addAll(seleccionadas);
    JComboBox laux = new JComboBox(AuxSeleccionadas);
    laux.setEditable(false);
    laux.setSelectedIndex(0);
    laux.setFont(new Font("Tahoma", Font.ITALIC, 12));
    //p2.add(lo);
    p2.add(laux);//para que se mantengan las anteriores al aadir nuevas.
    p2.add(new JPanel());
    ng++;
    //p.add(l);
    p.add(p2);
    String l2 = "                  ";
    if (c == 1) {
        if (ejeDual.contentEquals("dual"))
            l2 = l2 + "Consulta: Evolucin temporal dual, ";
        else
            l2 = l2 + "Consulta: Evolucin temporal, ";
    } else if (c == 2) {
        if (ejeDual.contentEquals("dual"))
            l2 = l2 + "Consulta: Acumulacin por intervalos temporales dual, ";
        else
            l2 = l2 + "Consulta: Acumulacin por intervalos temporales, ";
    } else if (c == 3)
        l2 = l2 + "Consulta: Mx-Mn-Med por intervalos temporales, ";
    else if (c == 5)
        l2 = l2 + "Consulta: Evolucin de diferencias en %, ";
    else if (c == 6)
        l2 = l2 + "Consulta: Evolucin de diferencias, ";
    if (f == 1)
        l2 = l2 + "de un intervalo.";
    else if (f == 2)
        l2 = l2 + "completa.";
    l = new JLabel(l2);
    l.setFont(new Font("Tahoma", Font.PLAIN, 12));
    p.add(l);
    l2 = "                  ";
    if (f == 1) {
        l2 = l2 + "Desde " + fini + " hasta " + ffin;
        if (c == 2 || c == 3)
            l2 = l2 + " con rango de " + rango + " horas.";
        if (c > 4)
            l2 = l2 + " con rango de " + rango + " minutos.";
    }
    if (f == 2) {
        if (c == 2 || c == 3)
            l2 = l2 + "Con rango de " + rango + " horas.";
        if (c > 4)
            l2 = l2 + "Con rango de " + rango + " minutos.";
    }
    l = new JLabel(l2);
    l.setFont(new Font("Tahoma", Font.PLAIN, 12));
    p.add(l);
    mantenerVista(p);
    //EN ESTE PUNTO DEL CDIGO, ANTES DE RESTABLECERVALORES, INVOCAR A LAS CONSULTAS (al constructor)
    //PARA GENERAR LA CONSULTA CORRESPONDIENTE ANTES DE OBTENER LOS PARMETROS DE LA SIGUIENTE CONSULTA.
    //nh indica el hilo que se tiene que coger para la consulta actual.
    try {
        if (nh == 1) { //Los hilos en su constructor llaman start.
            h1 = new Consultas(H, c, f, fini, ffin, rango, direcciones, NombreCarpetaActual, dataSource);
            h1.start();
        } else if (nh == 2) {
            h2 = new Consultas(H, c, f, fini, ffin, rango, direcciones, dataSource);
            h2.start();
        } else if (nh == 3) {
            h3 = new Consultas(H, c, f, fini, ffin, rango, direcciones, dataSource);
            h3.start();
        } else if (nh == 4) {
            h4 = new Consultas(H, c, f, fini, ffin, rango, direcciones, dataSource);
            h4.start();
        }
        nh++;
    } catch (IOException e) {
        e.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    consultasDuales.add(ejeDual);
    JPanel gen = new JPanel();
    gen.setLayout(new GridLayout(2, 1));
    gen.add(new JPanel());
    gen.add(generar);
    obtenidos.add(gen);
    reestablecerPaneles();
    cargarVista();
}

From source file:org.apache.jasper.compiler.JspConfig.java

/**
 * Find a property that best matches the supplied resource.
 * @param uri the resource supplied./*w  ww . j  av  a2  s .  c om*/
 * @return a JspProperty indicating the best match, or some default.
 */
public JspProperty findJspProperty(String uri) throws JasperException {

    init();

    // JSP Configuration settings do not apply to tag files       
    if (jspProperties == null || uri.endsWith(".tag") || uri.endsWith(".tagx")) {
        return defaultJspProperty;
    }

    String uriPath = null;
    int index = uri.lastIndexOf('/');
    if (index >= 0) {
        uriPath = uri.substring(0, index + 1);
    }
    String uriExtension = null;
    index = uri.lastIndexOf('.');
    if (index >= 0) {
        uriExtension = uri.substring(index + 1);
    }

    Vector includePreludes = new Vector();
    Vector includeCodas = new Vector();

    JspPropertyGroup isXmlMatch = null;
    JspPropertyGroup elIgnoredMatch = null;
    JspPropertyGroup scriptingInvalidMatch = null;
    JspPropertyGroup pageEncodingMatch = null;

    Iterator iter = jspProperties.iterator();
    while (iter.hasNext()) {

        JspPropertyGroup jpg = (JspPropertyGroup) iter.next();
        JspProperty jp = jpg.getJspProperty();

        // (arrays will be the same length)
        String extension = jpg.getExtension();
        String path = jpg.getPath();

        if (extension == null) {

            // exact match pattern: /a/foo.jsp
            if (!uri.equals(path)) {
                // not matched;
                continue;
            }

            // Add include-preludes and include-codas
            if (jp.getIncludePrelude() != null) {
                includePreludes.addAll(jp.getIncludePrelude());
            }
            if (jp.getIncludeCoda() != null) {
                includeCodas.addAll(jp.getIncludeCoda());
            }

            // For other attributes, keep the best match.
            if (jp.isXml() != null) {
                isXmlMatch = jpg;
            }
            if (jp.isELIgnored() != null) {
                elIgnoredMatch = jpg;
            }
            if (jp.isScriptingInvalid() != null) {
                scriptingInvalidMatch = jpg;
            }
            if (jp.getPageEncoding() != null) {
                pageEncodingMatch = jpg;
            }
        } else {

            // Possible patterns are *, *.ext, /p/*, and /p/*.ext

            if (path != null && !path.equals(uriPath)) {
                // not matched
                continue;
            }
            if (!extension.equals("*") && !extension.equals(uriExtension)) {
                // not matched
                continue;
            }

            // We have a match
            // Add include-preludes and include-codas
            if (jp.getIncludePrelude() != null) {
                includePreludes.addAll(jp.getIncludePrelude());
            }
            if (jp.getIncludeCoda() != null) {
                includeCodas.addAll(jp.getIncludeCoda());
            }

            // If there is a previous match, and the current match is
            // more restrictive, use the current match.
            if (jp.isXml() != null && (isXmlMatch == null
                    || (isXmlMatch.getExtension() != null && isXmlMatch.getExtension().equals("*")))) {
                isXmlMatch = jpg;
            }
            if (jp.isELIgnored() != null && (elIgnoredMatch == null
                    || (elIgnoredMatch.getExtension() != null && elIgnoredMatch.getExtension().equals("*")))) {
                elIgnoredMatch = jpg;
            }
            if (jp.isScriptingInvalid() != null
                    && (scriptingInvalidMatch == null || (scriptingInvalidMatch.getExtension() != null
                            && scriptingInvalidMatch.getExtension().equals("*")))) {
                scriptingInvalidMatch = jpg;
            }
            if (jp.getPageEncoding() != null
                    && (pageEncodingMatch == null || (pageEncodingMatch.getExtension() != null
                            && pageEncodingMatch.getExtension().equals("*")))) {
                pageEncodingMatch = jpg;
            }
        }
    }

    String isXml = defaultIsXml;
    String isELIgnored = defaultIsELIgnored;
    String isScriptingInvalid = defaultIsScriptingInvalid;
    String pageEncoding = null;

    if (isXmlMatch != null) {
        isXml = isXmlMatch.getJspProperty().isXml();
    }
    if (elIgnoredMatch != null) {
        isELIgnored = elIgnoredMatch.getJspProperty().isELIgnored();
    }
    if (scriptingInvalidMatch != null) {
        isScriptingInvalid = scriptingInvalidMatch.getJspProperty().isScriptingInvalid();
    }
    if (pageEncodingMatch != null) {
        pageEncoding = pageEncodingMatch.getJspProperty().getPageEncoding();
    }

    return new JspProperty(isXml, isELIgnored, isScriptingInvalid, pageEncoding, includePreludes, includeCodas);
}

From source file:opendap.threddsHandler.ThreddsCatalogUtil.java

private Vector<String> getAccessURLs(String urlPath, String serviceName, HashMap<String, Element> services,
        String baseServerURL) throws InterruptedException {

    Vector<String> accessURLs = new Vector<String>();
    String access, base, serviceType, sname;
    /* Iterator i; */
    Element srvc;//from w  w w  . j a  v a2  s.  com

    Element service = services.get(serviceName);

    if (service != null) {
        serviceType = service.getAttributeValue("serviceType");

        if (serviceType.equalsIgnoreCase("Compound")) {
            Iterator i = service.getChildren("service", THREDDS.NS).iterator();
            while (i.hasNext()) {
                srvc = (Element) i.next();
                sname = srvc.getAttributeValue("name");
                Vector<String> v = getAccessURLs(urlPath, sname, services, baseServerURL);
                accessURLs.addAll(v);
            }

        } else {
            base = service.getAttributeValue("base");
            access = baseServerURL + base + urlPath;
            accessURLs.add(access);
            log.debug("####  Found access URL: " + access);

        }
    }

    return accessURLs;
}

From source file:org.openflexo.foundation.ie.IEWOComponent.java

public void getAllDateTexfields(IETopComponent top, Vector<IETextFieldWidget> v) {
    if (top instanceof IEBlocWidget) {
        IEBlocWidget block = (IEBlocWidget) top;
        v.addAll(block.getAllDateTextfields());
    } else if (top instanceof IEHTMLTableWidget) {
        v.addAll(((IEHTMLTableWidget) top).getAllDateTextfields());
    } else if (top instanceof IESequenceTopComponent) {
        Iterator<IETopComponent> i = ((IESequenceTopComponent) top).iterator();
        while (i.hasNext()) {
            IETopComponent obj = i.next();
            getAllDateTexfields(obj, v);
        }//from w  w w  .  j  av a  2s .c o m
    }
}