Example usage for java.lang String regionMatches

List of usage examples for java.lang String regionMatches

Introduction

In this page you can find the example usage for java.lang String regionMatches.

Prototype

public boolean regionMatches(int toffset, String other, int ooffset, int len) 

Source Link

Document

Tests if two string regions are equal.

Usage

From source file:org.apache.webdav.lib.WebdavResource.java

/**
 * Set WebDAV properties following to the given http URL.
 * This method is fundamental for getting information of a collection.
 *
 * @param responses An enumeration over {@link ResponseEntity} items, one
 * for each resource for which information was returned via PROPFIND.
 *
 * @exception HttpException// w  ww  . j ava  2  s.c om
 * @exception IOException The socket error with a server.
 */
protected void setWebdavProperties(Enumeration responses) throws HttpException, IOException {

    // Make the resources in the collection empty.
    childResources.removeAll();
    while (responses.hasMoreElements()) {

        ResponseEntity response = (ResponseEntity) responses.nextElement();

        boolean itself = false;
        String href = response.getHref();
        if (!href.startsWith("/"))
            href = URIUtil.getPath(href);
        href = decodeMarks(href);

        /*
         * Decode URIs to common (unescaped) format for comparison 
         * as HttpClient.URI.setPath() doesn't escape $ and : chars.
         */
        String httpURLPath = httpURL.getPath();
        String escapedHref = URIUtil.decode(href);

        // Normalize them to both have trailing slashes if they differ by one in length.
        int lenDiff = escapedHref.length() - httpURLPath.length();
        int compareLen = 0;

        if (lenDiff == -1 && !escapedHref.endsWith("/")) {
            compareLen = escapedHref.length();
            lenDiff = 0;
        } else if (lenDiff == 1 && !httpURLPath.endsWith("/")) {
            compareLen = httpURLPath.length();
            lenDiff = 0;
        }

        // if they are the same length then compare them.
        if (lenDiff == 0) {
            if ((compareLen == 0 && httpURLPath.equals(escapedHref))
                    || httpURLPath.regionMatches(0, escapedHref, 0, compareLen)) {
                // escaped href and http path are the same
                // Set the status code for this resource.
                if (response.getStatusCode() > 0)
                    setStatusCode(response.getStatusCode());
                setExistence(true);
                itself = true;
            }
        }

        // Get to know each resource.
        WebdavResource workingResource = null;
        if (itself) {
            workingResource = this;
        } else {
            workingResource = createWebdavResource(client);
            workingResource.setDebug(debug);
        }

        // clear the current lock set
        workingResource.setLockDiscovery(null);

        // Process the resource's properties
        Enumeration properties = response.getProperties();
        while (properties.hasMoreElements()) {

            Property property = (Property) properties.nextElement();

            // ------------------------------  Checking WebDAV properties
            workingResource.processProperty(property);
        }

        String displayName = workingResource.getDisplayName();

        if (displayName == null || displayName.trim().equals("")) {
            displayName = getName(href, true);
        }
        if (!itself) {
            String myURI = httpURL.getEscapedURI();
            char[] childURI = (myURI + (myURI.endsWith("/") ? "" : "/") + getName(href, false)).toCharArray();
            HttpURL childURL = httpURL instanceof HttpsURL ? new HttpsURL(childURI) : new HttpURL(childURI);
            childURL.setRawAuthority(httpURL.getRawAuthority());
            workingResource.setHttpURL(childURL, NOACTION, defaultDepth);
            workingResource.setExistence(true);
            workingResource.setOverwrite(getOverwrite());
        }
        workingResource.setDisplayName(displayName);

        if (!itself)
            childResources.addResource(workingResource);
    }
}